Sorry, I do what you describe for specific instances, but don't use OBSE, so no while loops. The basic idea avoids a sometime problem where, for example, you enable a lite candle and disable an unlit one and the light doesn't appear as it should. If you set the light (candle in this case) to zero output and make the switch, including an "invisible" light source as you suggest, it always works.
Rather than searching for the nearest set of objects that match, how about using a standard naming sequence (eg: uniquenameLightOff, uniquenameLightOn, uniquenamePhantomLight). Then you can just copy you standard "light switch" script and make the changes for the specific instances quite easily (global search and replace with any decent editor). I know it's not as much fun as your approach, but it is a lot simpler.