First, I'd change the trans oil a few times, if you haven't changed it on a yearly basis. Next, check the fluid level. Dex/Mercon for fluid.
Next, I'd unplug the trans computer. You will need to manually shift. Also, it will not 'brake'. So, you will need to apply brakes, and get to the proper speed or RMP to down shift.
If this functions OK, then your issues are probably electronic. Check the Solenoids as suggested. There are about 5 or more sensors that control the trans. The solenoids, the two speed sensors, the TBS, the brake switch, the trans computer, the NSS (Range Selector for 98+), ECM. Also, could be an electrical issue. Check you battery. Then you might check voltage at certain locations.
As to 'junkyard' parts, it can be luck of the draw. I've had two bad motors from JY's. I did have a trans replaced this past year. I am selling off one of my XJs. So, I wanted to keep the trans I had rebuilt about 5 years ago. A guy who works on Jeep that I use had some AW4s. I had him swap in one. $100 or $200 for the trans and $200 labor. Yeah, cheap. Works good.
He did have another trans there last week. Looked almost new. No TC though.