I would take a look at car-part.com (Hot-line database for junkyards) for a used or reman engine. Used there avg $600 @ approx 100,000+ miles, Remans are $1600 with warranty.
The swap can be done. This site will give you an idea of the all the required items. I wouldn't say its real cost effective.
Swapping An Explorer 5.0L In To A 1998-Up Ranger