What's wrong with my 2004 Ford F150 Lariat?

I have a 2004 ford f150 5.4 triton3v. 137000 miles. The truck will run while cold for about 20 minutes until it is up to normal running temp then start to drop rpms, shutter then shut off. If I attempt to put it in drive or reverse, it will do the same thing, drop rpms and then shut off. I have replaced the TPS, as well as the throttle motor, it has an electronic throttle on it. I have also unhooked the battery and placed both negative and positive together to drain the PCM for more than a minute and no difference. If I get it on the road and drive it, it runs fine until I come to a stop at which point it stalls again. I also had a code for a cylinder 4 missfire so I replaced the coil for that, not to mention the fact that I just replaced all spark plugs three weeks prior. Please help, I don't know what else to do. No other codes have come up.

Gas cap valve hangs and creates a vacuum in the tank the fuel pump can't overcome… Loosen it go for a drive. Seen it dozens of times a few failed OEM, but most fairly new aftermarket. The OBDII may detect this leak and set a code during the test, but it'll erase it shortly after it's tighten/replaced. I've stocked/used only Ford/Motorcraft caps after seeing the failure rate of the others. If yours isn't the cap let me know.