Intermittent problem like this is often caused by bad connection on the code key ecu. Remove 2 connectors, spray with electrical contact cleaner and replace. I make that sound easier than it is though, as the code key ecu is located above and left of the fusebox, behind the dash. It is a black box about 4"x2"x1" with a green sticker and two white connectors, held in place by two 10mm bolts, one of which is a real pain to get to. If you're very lucky, you might be able to get to the connectors without having to remove the box.
Other causes of this problem are bad connections/corroded terminals on the power supply relays located near the battery. Also broken wires in the loom near the engine ecu connectors, faulty code ecu, faulty engine ecu.
But try the easy, simple, not to mention cheap, fix first!