As the car has been doing this for a period of time but starts OK which suggests the battery has been getting charged sufficiently, so I doubt that it's the alternator. In the main fuse/relay junction box there is a relay called the power hold relay that puts battery power through a hot at all times 20 amp. fuse to the PCM when the Ign. switch is at On or Start. After checking the battery connections as suggested, I'd swap out this relay. It should be common knowledge by now, but I"ll repeat it.......NEVER, EVER disconnect the battery when the Ign. switch is selected ON, including any attempt to see if the alternator is producing current. It's a good way to zap the PCM and/or the alternator. The FSM for any modern car will have this warning.