It could be a number of things and going through the below list on your stalling problems is a real good place to start.
You may want to get a fuel pressure tester and connect it to the schroeder valve on the rail to see what your pressure reads. Spec for your 98 4.0 is 49psi at idle when the engines at operating temps and shouldn't drop below 24psi after 5 mins from when shut off.
You can get a loaner fuel pressure test kit at Autozone, pay full price of $100, keep for 90 days, and return for a full refund. I kept the one I borrowed for a full 2 months until I put a new fuel pump assembly in but my problems were a little different than yours.
Not a bad idea to rule out a bad crank sensor too for stalling problems. You can unplug the connector at the back passenger side of the head. Then hold the plug to the sensor itself with the locking tab up and put the probes of a multimeter, set to the lowest ohm setting, on the middle and right pins (B&C). Any resistance = bad CKP.
BTW, ZeeJay who wrote the excellent thread in the link had a 97 4.0 with a clogged cat so you may want to look at that section closely on loosing power. Believe it's in there. Good luck.