It sounds like you have 2 problems going on here. First the Idle Air Control Valve , IACV, has failed or needs cleaning. It is located on the intake manifold near the throttle body. Second, when you install a new battery sometimes it takes a little coercing to get things to isle correctly. This walk through will explain. Just folow link below to get to it;
If you decide to clean the IACV then make sure to use brake cleaner and spray inwards towards the intake tract and clean the ports on the intake manifold as wel in the same fashion. This keeps deposits from being pushed closer to the IACV.