Well from the sounds of things, the Neutral Safety Switch has been at wits end for a while now. Either measure that out or replace it and hope. ALSO check the wires going to this sensor as its close to the exhaust.
I agree that the symptoms indicate a problem with the neutral safety switch (aka the XYZ switch). I had this happen in my truck 10 years ago last month.
You can check the switch by moving the shifter through PRND321 and observing whether the gears selected are indicated correctly in the instrument panel. If there's a problem, the instrument panel indicator may be blank when you select P or N.
Before replacing it, I would try adjusting it. To adjust it, set the parking brake or chock the wheels, and have an assistant sit in the driver's seat, turn the key to Position II and the shifter in the P position. Next, loosen the two mounting bolts with 10mm heads (just a little; do not remove them). There's no need to loosen the 13mm nut on the selector shaft. Rotate the switch on the selector shaft carefully from one extreme to the other, with your assistant observing the instrument panel indicator. If the P appears in the instrument panel, tighten the mounting bolts and you're done.
If you can't get P to appear in the instrument panel, have the assistant move the shifter to N and repeat the process, looking for N to appear in the instrument panel.
If this doesn't correct the problem, you can try disassembling and rebuilding the switch. There are tutorials in the forums and probably on YouTube.
BTW, if you rebuild the switch or buy a replacement you can use the same procedure to adjust the switch when installing it.
PRO TIP: I find it easier to lie under the truck with my feet on the passenger side of the truck.