Stephen,
Highly unlikely engine ECU will lose the code everytime the battery goes flat as it's on an Eprom.
Only other place that the immobilisation code is kept is in the BECM and this is logged as the "Lockset Code" which is unique to your car and keyfob.
When you put the key in the ignition switch, an exciter ring around the swith body excites the key fob to transmit it's code to the alarm system and the BECM-if the lockset code (13 digits) matches, the BECM enables the engine ECU to become active and allow the engine to start.
I have known the BECM to become corrupt but it's rare and not an everyday occurence even when the battery is disconnected. When the engine was replaced in my 4.6, the battery was off the car for over 3 weeks and apart from the usual window resets etc. all powered up o.k.
You obviously have a problem but I don't think it's as "Terminal" as you think.