You have 2 issues, mechanical and electrical. They can be overcome.
Mechanical- It's a bolt in with the right parts. As stated above the trans bell housing is different so you need a 4.0 trans and dipstick. Exhaust is different so you need a crossover for the 4.0. All the accessory mounts are different s well as the power steering pump and starter. Throttle cable and cruise cable(if equipped) are also different.
Electrical- PATS system=Passive Anti Theft System(the proverbial pain in the a** for engine swaps) The ECM(and other components) have the VIN programmed into them as well as the chip that's located in the ignition key. You can put everything together just right and the PATS system will prevent it from even turning over. The solution- get everything including the keys from a parts truck with a 4.0, or take it to the dealer to get it programmed. First things first. Your truck is a 03 and the motor is a 04 or newer=problem. In 2004 Ford changed all the wiring including the instrument cluster on Rangers. The motor will work just fine but you have to decide which way you want to go on wiring. 2004 and newer means basically rewiring the whole truck with newer harnesses. 2001-2003 wiring and you should be able to just change the engine harness, ECM, ignition switch and maybe the restraints module. I am not positive on this and would need to be verified by someone who has done the swap, I have not. Anytime you change harnesses in a Ranger they have to match your trucks equipment suach as 4WABS or RABS(rear anti lock brakes), Power Windows, Cruise...ect.
00 2wd ext cab wrecked
00 4wd ext cab rebuilt-04 front end
06 Cobalt (Wifes Car)
99 Ext Cab 01 front
04 Edge parts truck
98 2wd reg cab 2.5 auto-sold
99 Ext Cab 4wd 3.0/5sp rebuilt-sold
01 Edge Ext cab 2wd 3.0/auto-dismantled
98 2wd reg cab 2.5/auto-sold
98 4wd 4.0/auto-sold
94 Ext cab 4x4 4.0/5sp-sold
98 Ext cab 4x4 4.0 auto-parted
94 2wd reg cab 2.3/5 sp-traded
89 2wd reg cab 2.3/5 sp-sold