I've had this issue since I got the Jeep (used) and I thought I'd write about it.
When I got my tj it had a check engine light on. Previous owner told me he would just disconnect the battery and it would go away for a while. What he didn't tell me was that the fuel gage would, at random times, register empty and the low fuel light would light up. Then the check engine light would show after this happened a time or 2. I changed an O2 sensor that was also throwing a code.
I read that higher sulfer content in some cheaper gasolines will cause a buildup on some sensors and cause them to fail or error. I also read that Chevron makes 1 additive that will help to clean excess sulfer from sensors, I tried it. Also read what Gas companies have less sulfer content in their gas and started using only gas from those companies. (It was an article in Westways magazine, put out by AAA - autoclub - I don't remember all the details and don't have the mag handy).
I'm happy to say that, between the additive and gasoline, the problem has just about dissappeared. In the 3 months following I only had 1 reoccurance of the fuel gage problem/low fuel light/check engine light. The tank was low at the time, and after filling the tank everything went back to normal.
I know that I should change the fuel level sensor, and will do so when I drop the tank to convert it to the 19 gal. that it is supposed to be. But until then, I am happy with the results of this "fix".