Common answer is yes it will fit - how much tme, money and experience/skills do you have? The 4.6 swap is getting to be done more and more but still not all that easy. Like 85_Ranger says, the 5.0 Explorer motor is so close to being a drop in swap The '04' Mustang Cobra put out 380 HP with it's DOHC motor. Bet it would cost a lot less to reach that with the 5.0. Ought to check what a cam change costs on just a SOHC 4.6. Don't get me wrong, love the new mod motors, love to have a 3-v 4.6 in mine but it'd have to be SC'd to get the full benifit.
Dave
One other good link to a 4.6 build is the one done by GregR, first one to do it
http://www.cardomain.com/ride/2052265/1998-ford-ranger-regular-cab/page-6/
Cam change isn't that expensive. MMR will degree a cam for anyone who is lazy and the kit to change the cams is only $80 and can be rented. The 4.6L will fit pretty easily in the engine bay the 5.4L will as well, but the deck height and stock intakes are taller. The 5.4L DOHC has been done which is taller and wider than both. The thing for any of the mod motors is getting heads that flow. Trickflow heads cost money, but they embarass all other heads for flow (based off the old 427 SOHC motors you know the ones banned from nascar).
Engine dimensions
4.0L SOHC (440lbs)
302 dimensions w/ carb
height: 27" length: 29" width: 22" wide
4.6L SOHC Mustang Intake (500lbs)
height: 26" length: 23 5/8" width:
5.4L SOHC F-Series Intake (525lbs)
height: 28" length: 23 5/8" width: 27"
4.6L DOHC Cobra Intake (425lbs)
height: 27 1/8" length: 23 5/8" width: 26 5/8"
4.6L DOHC Sullivan Intake (425lbs)
height: 27 3/4" length: 23 5/8" width: 26 5/8"
5.4L DOHC Navigator Intake (540lbs)
height: 35 1/2" length: 23 5/8" width: 28 1/4"
6.8L SOHC V-10 Van Intake (640lbs)
height: 28 1/2" length: 27 1/8" width: 27