The cause could be from several sources but I would start with the PCV tube that connects on the passenger side of the throttle body. It is right under the top radiator hose. Look for a rubber elbow that connects to the throttle near the front. This elbow tends to deteriorate resulting in a vacuum leak or it can partially collapse.
I had a tough time finding my rough idle problem and finally lightly sprayed starter fluid around the throttle body until the engine surged. Upon inspection of the elbow I found it to be in bad shape and was cracked. I replaced it with a silicone elbow and the problem was solved.
2002 FX4 Bright Red Supercab 4.0 SOHC, manual 5-spd & Tcase, 33" BFG MTs, K&N air filter, Modified air box inlet, Gibson SS cat. back exhaust, Bama flash, Hidden Hitch round receiver, Rear helper air springs, Electric trailer brake controller, Line-X bed liner, WAAG bar with KC lights and Wildernest shell.