if i were looking at a V8 swap i'd throw the $$ at the 340. it's smaller, lighter, and revs faster. the latter not really being a concern unless you are gonna race the XJ, at which point i'd tell you save your $$ anyways. the automatic in the TJs was a torqueflite 999, at least for the first few years. THAT will bolt up to the 340, and match it with a 231 and you are on your way. i dont think the TJ trans/t case are longer than the AW4/231 since it comes from a much shorter wheelbase rig.
have you been realistic with yourself about everything else that comes with a V8 swap? exhaust, fuel, electrical, uni-body strengthening??
food for thought... are you prepared for a $10K engine swap into a used Jeep? it adds up fast!!
a nice stroker might be a better choice.