You can use any Ranger 3.0l OHV or Mazda B3000 engine from 1995 thru 2008(last year) to swap into any other year Ranger/Mazda with 3.0l OHV
As said just use the block and heads and swap over intakes to match your years wiring/plumbing
You can use a 1991-1994 Ranger 3.0l OHV but need a different timing chain cover and crank balancer for crank sensor
3.0l OHV Taurus/Sable car engines can also be used, but you need to change the head gaskets for proper cooling
While ANY engine is out, change the rear main seal
On the 3.0l also change the front timing cover gasket, common coolant leak point, front main seal is part of that as well
3.0l has a metal elbow on the front of lower intake, it can rust out, and hard to change with accessory brackets installed as its a threaded fitting
New oil pump is never a bad idea or new oil pan gasket, but judgment call