Have the battery laod tested at a shop or parts store.
When the battery goes bad or you run it down by leaving the lights on, the engine computer re-boots and the idle settings are lost. The symptoms are, difficult to start, only runs if you keep your foot on the gas, runs fine after a few moments (the idle setting are relearned until the next time).
A bad battery may have enough power to start the engine but the low voltage cause the computer to re-boot.