for emmisions you need to go with a newer v-8 depending on the state then the year engine you have. in general. it varies state to state and my state it has to look stock. if you have a 3.0 engine count on changing the transmission also. i dont know about the 4.0, but you should any way because the transmission is weak.
the years explorers had v8 from the factory is i thing 95 and newer. but people put in 4.6s and 5.0 from mustnags and thunderbirds as well as from f-150s all the time. its not that much harder its just a matter of getting all of the parts. below are the "put a v-8 in a ranger" sections of the most popular ranger forums. and most if not all of the figuring has been done so all you have to do is read and swap.
V8 Tech - Ranger Power Sports Forum
V-8 Conversion Forums - The Ranger Station Forums
Ford Ranger V-8 Engine Swap