Hello and welcome to JustAnswer!
This is normally caused by the idle air control motor (IAC) not responding. It's mounted to the back of the throttle body with 2 T-20 Torx screws. The IAC is what lets air into the engine when the throttle is closed. If it doesn't respond correctly when commanded then the engine won't get enough air with the throttle closed and it won't idle, in some cases you can even flood the engine if you keep cranking on it without opening the throttle.
When your battery has been low or disconnected it can cause this. Address any problems you are having with the battery first. If the battery seems low or the engine is cranking slow you'll need to get the battery tested, replace it if necessary. When battery voltage gets low enough during cranking it will corrupt the engine controller's memory, and it won't know where the IAC's position is. There is no feedback on the iac, the controller commands it to move but it has no way of knowing if it actually did.
Once the battery situation is taken care of remove the IAC from the back of the throttle body. Clean it and the bore it moves in with some carb cleaner. Remove all carbon, the carbon stops free movement of the motor. Move the pintle of the IAC in and out a little by hand to make sure its free. They can develop a hard spot in the travel and stop moving, this may free it up. If it doesn't free up and move smoothly in and out, replace it.
Clean all of the carbon from the throttle blades and the bores the throttle blades are in. This area also has to be clean for the engine controller to control the IAC properly. It's control strategy relies on the correct small amount of air past the throttle blades.
When you get the throttle body reassembled turn the key on but don't start the engine right away. Wait a few seconds and then start the engine. You may have to bring the RPM's up when you first start it. Bring it back to idle very very slowly. Do this a couple times if you have to and then it should run ok. If it doesn't, you may have to replace the IAC (if you haven't already at this point) in some cases, or the engine controller's memory may need to be reset with a dealer scan tool. This would only take a couple minutes of their time.