No real idea about phasers in vacuum... Save for the observed facts that
1) we have never seen a phaser beam fade out or otherwise terminate in vacuum, but
2) our heroes always try to fight their space phaser fights at minimum distance, which may well suggest the beams weaken out a lot with distance and will become harmless in just a few lightseconds, and
3) in "Balance of Terror" it was possible to set phaser bolts to explosively dissipate at a distance ("proximity blast mode"), suggesting the bolts are normally held together by some sort of a sheathing force, which may have a finite lifetime and thus spell explosive death to the phaser beam at a set distance.
As for photon torpedoes, they would probably have self-destruct charges that activate when there is no more fuel for maneuvering and trying to acquire another target. Plus a remote detonation option, although in wartime this would be a weakness if the enemy learned the detonation codes; scuttling thus is probably designed to be very difficult, explaining how our heroes had so much trouble with a maverick torp in "Genesis".
On the other hand, torpedoes supposedly use their warhead for fuel, at least according to the tech books. So basically a torpedo could be programmed to run until there is no more antimatter there, meaning that not only does the torp lose the ability to maneuver, it also has lost the ability to blow up, and can be left to its own devices.
Timo Saloniemi