2004-2006 Ranger 3.0ls had exhaust valve seat problems, the seats can be changed or the heads swapped for newer versions.
That would be least expensive solution.
Any year 3.0l Vulcan engine can be used, Ranger or Mazda B3000 is best, but the car 3.0l Vulcan can also be used.
You will need to swap your upper intake to new engine so wiring matches up.
You of course would want to avoid the 2004-2006 3.0l's.
Getting a used engine is a roll of the dice, no history.