Yes you should be able to swap it out for a 1997 4.0l, might have to change flywheels depending on transmission.
Also swap intakes so sensors are all the same for '93 wiring harness, no ECU change if sensors are the same.
Not sure on the EGR system in '97
Here are the 4.0l details
http://www.therangerstation.com/tech_library/4_0_Page.html
I would lean towards just fixing the head gaskets, I did my '94 4.0l head gaskets and at over 300,000 now, bottom end still sounds solid.
Coolant in the oil is a sure sign of head gasket issue.
Pressure in the cooling system when engine is cold is another sign, if overflow tank starts to bubble or fill with coolant as soon as you start the engine then head gasket or cracked head is most likely the issue, the heads on the 4.0l are prone to crack between the valve seats.
White smoke out the exhaust is also a sign but on a cold day it can be normal evaporation as exhaust heats up.
If you engine is just overheating there are other causes.