Now I'm not exactly positive this might be the same issue as your question is very general. If your truck idles and it revs up and down randomly while pressing on the brake or the gas petals, it may be your throttle positioning sensor.
I had this problem with my Honda Accord a while back. While I was braking I would see my RPM's spike a little and then bottom out. When I'd accelerate, sometimes the RPMs were unpredictable and seemed sticky when I got up to my cruising speed. I was worried there may be a transmission problem, but when I hooked up the device that reads your vehicles OEM codes (Auto Zone did this for free), it clearly indicated the malfunction related to the Throttle Positioning Sensor.
I hope this helps.