hello and welcome to just answer!
I need to know what year make and model your vehicle is so I can help you. Also engine size would be helpful.
thanks and look forward to helping you out!
try disconnecting the battery again. While the battery is disconnected, remove the air breather from the engine and clean the throttle plates. make sure all carbon is removed and the throttle body bore and throttle plate is clean.
re install the battery cables and start it up. give it a few minutes to relearn the idle strategy. It sounds like you have carbon build up in the throttle body. When the battery was disconnected, it lost it's idle strategy so it's basically trying to relearn the strategy with carbon blocking the throttle plates and it's haveing a hard time. cleaning the throttle plates should allow it learn the idle.
If this helps you please press accept! Rest assured if you need any more help, just let me know!