Hello, I am John, a Ford dealer technician.
I hope I can help solve your problem quickly and accruately.
Sounds like you have a bad IAC valve. This is located on top of the engine and is known to stick causing your problem. Sometimes you can tap on this with a hammer and it will start working but you still need to replace it.
This is what it looks like.
If you have the sohc 4.0 this is under the cover that covers the intake. If you have the ohv 4.0 it is on the side of the valve body.
I hope this answer has been helpful to you! If you have any further questions please feel free to ask.
If this answer has been helpful please accept so I can recieve payment. Feedback is very
important to me so please leave accurate feedback for others to see my job performance.