A failing CRANK SENSOR acts like this. It breaks down when heated up, but returns to use when the engine cools down. Get truck running, and go to a DIY car wash with a can of GUNK ORange.
SPray the living heeck out of the engine, and focus on the engine front where the CRANK SENSOR lives. Remove ALL traces of grime and grunge from engine bay. Clean the space between the radiator and the A/C condenser where seedlings, leaves, animal droppings, and paper collect.
This will restore good BREATHING to engine and trans, and keep the sensors cooled down. CLean engines ALWAYS save gas and give better smoother power. ALSO>>>>>>> remove and clean yorur IDLE AIR CONTROL valve for easier starts and better power.
It fine tunes your air/fuel mixture based on O2 sensor signals. Watch your mileage and power improve by doing this simple thing. CLean the THROTTLE body as well.
Consider using Mobil One 0W-30 engine oil, that will keep your lifters and oil pump happier and reduce friction, saving gas. GOOD LUCK!