If Melachah was done on Shabbath, can the product of that Melachah be enjoyed after Shabbath, and if so, under what criteria (does it depend on how long after Shabbath, or on the need, or something else)?
Based on Mishna Berura and Biur Halacha 318:
There are 3 variables which affect your answer:
There are two opinions about benefiting from a shabbos transgression-
Rabbi Meir: If the transgression was done knowingly (meizid), all may benefit from the act only after shabbos. If the transgression was done unknowingly (shogeg), all may benefit immediately
Rabbi Yehuda: We are stricter with the transgressor- If he did it knowingly, he may never benefit. If he did it unknowingly, he must wait until after shabbos. (All others are the same as R' Meir.)
There is a difference of opinion as to who we pasken like. The Shulchan Aruch by cooking (318:1) sides with Rabbi Yehuda. The Gra maintains that he only paskened so for Biblical prohibitions, but by rabbinic prohibitions, there is no penalty for an unknowing violation. Th Gra himself paskens like R' Meir.
If you are a Mishna Berura man:
All knowing violations, whether Biblical or rabbinic, are prohibited to the violator always and for everyone else until after shabbos- like R' Yehuda
Rabbinic, unknowing violations are permitted immediately to all. Biblical unknowing violations are still forbidden to the transgressor himself until after shabbos- like the Gra's version of the Shulcha Aruch
All unknowing violation, Biblical or rabbinic, in cases of necessity, are permitted immediately to all- like the Gra who paskens like R' Meir
In a case knowing case where a non-Jew was employed to violate the melacha, there may be an additional penalty after shabbos- the amount of time it took to perform the melacha- so that there is no nominal benefit.
In a case where there is an argument whether there is a violation, there is no penalty and all are permitted to benefit immediately.
If it was done by a non jew then it may be used after shabbat after you wait "Bi'Kdei Sh'Yaasu" the amount of time it took him to do the melakha.
If it was done by a jew it can be used immediately after shabbat. Orakh Haim 318.
A quick addition. If a person did it on purpose then he may not benefit from it even after shabbat.
The first seif from Orach Chayim siman 318 describes the situation in this case regarding food cooked on shabbat (mevashel). Ostensibly, it should apply to other cases as well - I suggest that you study the commentaries to this.