Very very tight squeeze, width wise.
302(5.0l) is 18-3/4" wide
351W(5.8l) is 21" wide, (these are tight but workable)
4.6L SOHC is 28-5/8" wide
4.6L DOHC is 30" wide
Length is the same for all, 28"
Height would also be tight so you would need to do a body lift
Good read here on the 4.6l: The Ford 4.6L Modular Engine
You would need a transmission for a Ford modular engine, any stock Ranger trans won't bolt up to it, and wouldn't last long in any case with the higher power.
In general this type of swap would be a full custom swap, meaning you will need to customize quite a few parts and engine compartment areas, so you will not just be "dropping it in" and running new wires.