Welcome to The Ranger Station!
It appears to have two problems.
We'll need more information about when it dies. Such as:
Can you hear the fuel pump run for two seconds when the key is turned to Run (do not crank the starter, just LISTEN for the fuel pump in the Run position, then Off, then Run again. It should hum for two seconds each time you go from Off to Run).
Is there SPARK at any of the spark plugs?
If it dies (stalls) when you LET OFF THE GAS, clean or replace the IAC on the throttle body. The Idle Air Controller controls the idle. If it is shutting off while your foot is giving it gas, it's NOT the IAC.
For the restarting, if it engages the starter when in any gear selection EXCEPT P or N, then you need to adjust or replace the DTRS. That is a Digital Transmission Range Sensor, which is commonly referred to as the Neutral Safety Switch (old terminology).
The DTRS is easy enough to replace, and located on the side of the trans at the spindle where the shift linkage is connected. Once installed, you adjust it such that the Reverse Lights come on in Reverse. Then, the starter will only engage in P or N, as it's supposed to. The DTRS should not cause the engine to shut off while driving.
It would also be helpful to know which engine is in this truck.