Normally what causes this issue on Injected XF's is the ISC unit is full of crap, remove it, spray degreaser/CRC through it, give it a good shake around and if you can, blow it out with an air compressor, get it REALLY clean. That's the first thing I'd try, is your timing correct? They also run a sealed crank case, so they are very suseptible to any sort of air leaks into the crank case, check the oil filller cap, dipstick seal, even the rubber neoprene seal on the oil filter, and make sure you have no oil leaks, even something as simple as a leaking rocker cover gasket can make these engines run crap. I highly doubt the EGR would cause it unless it's stuck on all the time, which I reckon would give you issues when driving too. Push it in and out a few times with a screwdriver to make sure it moves freely, but dont break the diaphram. Next could be the AFM, make sure it's plugged in, and make sure the flap inside it moves freely. That's about all you can check with the AFM, short of plugging in another one, and they are DEAR AS POISON to buy new, and even 2nd hand ones are above $50, so hope it's not that. A vaccumn leak I'd also consider unlikely to make it stall, but it will generalyl cause it to idle faster and make a hissing noise, and make it generalyl run crap. Check for any hoses off, and spray WD40 or aerostart around all the places where it can leak such as the manifold flanges. The other thing I would check is make sure you dont have a blocked PCV Valve, they are pretty common for them too. I think that pretty much covers it, try some of those things and let us know how you go.
Cheers, Gab