If you're looking for a motor that is IDENTICAL to the one in the 1998, then you'll want to look in the '96 to '98 years. Prior to '96, a different cylinder head was used (casting #7120), but I believe that this head will bolt directly to the intake/exhaust manifold of any year 4.0L. After '99 ('00 and '01 model years), the cylinder head was changed again for the much less desirable 0331 casting, which has shown a high rate of failure (it cracks between the 3 and 4 exhaust valves). There is something about the '99 year that is different than all of the others but I'm not quite sure what it is.
As long as a lot of the connecting parts on the '98 motor are good (sensors, manifolds, brackets, etc), you should be able to swap them over if you run into any issues.
I've also heard that Wrangler 4.0L engines have slightly different mounting holes on their blocks, but I'm not sure if this is true or not. I'll be acquiring a '00 TJ engine in a couple weeks so I could verify that information then, but I'm sure someone else will chime in before that.