Just had the same problem a month ago and after spending money on a new IAC, MASS air flow (tried cleaning them too), O2 sensors, spark plugs, and fuel filter, it turned out to be a ripped vacum line that runs along the head covers. But it also drove poorly and idled bad. So not sure if your truck runs fine when its warmed, or during operation. My truck also would come and go but eventually it gets really annoying, Hopefully this helps.
2003 Ford Ranger FX4 LVL II