Welcome to the forum.
2004 Ranger with factory 4.0l SOHC and you pulled that out and put in another 4.0l SOHC engine.
So same engines, right?
I would get or rent a fuel pressure gauge.
60-70psi is what you should see when engine is idling
Raise engine RPMs to about 2,500 and hold it there watch if fuel pressure starts to drop, if it does then fuel pump is most like starting to fail.
If fuel pressure is jumping around then you will get lean/rich codes and fuel trims, computer is trying to keep O2 sensors showing good burn but as pressure drops it opens injectors longer and longer to stop lean burn and then a jump in pressure causes it to go rich suddenly.
Video on finding schrader valve here: www.youtube.com/watch?v=F7mYC9JwMLg
Also back by the schrader valve there should be the Pulse damper, end of the fuel rail, it will have a vacuum hose attached, check this hose for fuel, shouldn't be any sign/smell of fuel in that hose, if damper leaks then fuel is sucked into engine, causing same symptoms.
Another test is for leaking fuel injectors, they are new which means never tested, not they work.
After engine is warmed up shut it off
Turn on the key
Press gas pedal to the floor and hold it down all the way
It should NOT start, or fire at all
All fuel injection computers have a "Clear Flooded engine" routine
With key on, computer on, engine off, if computer sees WOT(wide open throttle), gas pedal to the floor, it will enter clear flooded engine mode, it will shut off fuel injectors but leave spark on.
So when you crank the engine there should be no fuel in intake so no starting or firing at all.
As soon as you release gas pedal injectors will start, or if engine does fire enough and RPMs show above 400 then computer will restart injectors.
If engine does fire then you have fuel getting in to intake.
If you disable coil and do the same above test you could ID the leaking injector.
After cranking pull all the spark plugs, the wet one has the leaking injector
I would also buy a Fuel Pump Relay, just a standard car relay, under $8, while it is unusual for these to fail they do.
It is in the engine fuse box.