Get yourself some carb cleaner and an old toothbrush and clean your throttle body and IAC or "idle air controller". I bet the inside of the throttle body and the IAC is black. Easiest and cheapest place to start.
As far as your tranny, you have an Aisin Warner or AW4, also called the A340. Used in many years of XJ and YJ Jeeps, Toyota Supras and Land Cruisers, Volvos and I have even seen one in a small Mitsubishi box truck. Medium duty and almost bulletproof in the XJ if kept cool. I have run three of them for over 3/4 of a million miles, all on lifted Jeeps with over sized tires and used in extreme coonditions. All were original and never rebuilt. Again, KEEP IT COOL! If you drive it on the beach do not wait until the fluid needs to be changed. You do not have to change it all by dropping the pan just drain from the plug and refill. Also do not listen to your local Jeep dealer or anyone else about the fluid. Most dealers will put in ATF3 which is wrong and lead to many of the problems you may hear about the tranny. It is an older Japanese built tranny and requires Dexronlll/Mercron, or a suitable synthetic replacement.
If this does not work look at the TCU and TPS next. If you live on LI bring it by.