my old mj used to do many of the same things, one day the lights would work the next they wouldnt. no high beams, than all if asudden tehy just stopped working etc. i replaced the switch, the relay, the bulbs, and eerything else that seemed to be part of the system. one day an guy that works at a jeep dealer told me to check all the different wiring harness plugs under the hood, specificly by the firewall he thought one of the had something to do with the lights. sure enough there was a plug i want to say it had 6 wires going into it that made teh lights comeone when i wiggled it. turns ut when i cleaned it p the housing of the plug was cracked and the wies got loose not to mention dirt, mud, rain, oil, and grease. i cleaned it all up and taped it up good and water tight and with copious amounts of dielectric grease i neer had a problem with it again. i dont know if its the same on yours or not but it could be worth looking for.
1990 XJ, complete HO swap, approx 4" lift, 33 mt's, "trimmed" fenders, cobra CB, Homebrew roof light bar, 91' non disconnect front axle. various odds and ends.
"Friends don't let friends wrench alone"