The 4.0 liter Jeep inline 6 was an old design that was known for reliability problems. Most of the problems were in the electrical system. The engine you have (VIN code "S") was used in the Cherokee through 2001; the Wrangler through 2006, and used in the Grand Cherokee through 2004.
In 2002; the Jeep Liberty came out with a new motor. It was a modern 3.7 liter V-6 with double overhead cams and 4 valves per cylinder. This motor (VIN code "K") replaced the 4.0 as a base motor in the Grand Cherokee from 2005 to 2010. It was also used as the base motor in the Commander from 2006 to 2010. It was originally used with a Chrysler 4 speed automatic that was very similar to the transmission in you car; but in 2005; that transmission in the Liberty was replaced with a Mercedes Benz 5 speed automatic transmission (and the Grand Cherokee got a new Chrysler 4 speed automatic; but the Wrangler 4.0 continued using the old transmission). This motor would be a great upgrade for your car; but it would require some custom fabrication to make it work. The wiring harness, transmission, computer, and exhaust system would all have to be changed over. That might be more than you'd be up for; but perhaps not.
There is also an engine remanufacturer called Hiperformer Engines, in Spokane WA, who sells a premium quality remanufactured engine for your car for about $1,783 plus shipping. This motor has a 7 year, 100,000 mile warranty. There is a $300 core charge; which is refundable when you return the old motor to them. I think this is one of the best deals around on a quality remanufactured motor. They ship motors anywhere in the US. They also can add custom performance modifications to this motor, on request.