When I know that an encounter will happen in the next few minutes (like I already see/hear the enemies coming), and cast a spell that lasts till the end of the encounter (like Heroic Offense, target gets +1 till end of encounter), do the spells just fizzle? Or does it already count as "in encounter" because I know that there will be one?
I don't know if there is an official answer for this, but if you can already see or hear the enemies coming then the encounter has already started and I'd say it's fair game to cast the spell and expect it to last until the encounter ends. This would presumably be at the end of combat, though it'd also end if you heard guards coming, cast the spell, hid and then waited until they went past for example.
As for other scenarios where you might cast it in advance, if you were about to ambush someone on the far side of the door, I'd rule that it'd last the combat as if you'd cast it during the first round of combat (which essentially is what you did - the encounter started, you spent a round casting a spell, the enemy spends a round unaware of you doing whatever they were doing before, then you burst through the door in round 2).
If you were setting an ambush and didn't know when the enemies were going to arrive I probably wouldn't let you cast the spell until there was something you were encountering.