As mentioned a number of things can cause erratic idle speed... with the throttle position switch being at the top of the list...

If the TPS idle position contacts do not go closed (due to mis adjustment, wear, or dirt inside the throttle body) with the throttle all the way back to idle, the computer doesn't get that signal indicating that it should control the IAC to the correct position to get the proper idle speed..

There are tons of posts on TPS problems.. First thing you'd want to do is clean the throttle body per this article..