The symptom described (intermittent operation, better after reseating the batteries) is caused by poor connection, likely due to oxidized contact surface on either the battery cells or the contacts in the remote.
One thing that may help is to carefully and gently bent the remote contacts (or stretch the spring contacts) so they put a little more pressure on the battery -- but this may not be possible in many remotes. Rubbing the flat contact in the remote and both ends of each cell with a pink pencil eraser is likely to improve things a bit, as well (don't scrape with a metal tool or use an abrasive of any kind, as you'll remove the protective plating on the remote's contact plate). If there's any visible corrosion (from a prior set of failed cells) it must be removed.
If these measures don't solve the problem, it may make more sense to purchase a "universal remote" (typically under $20). Do try to check before purchasing that the remote supports your brand and model of television, but if the TV is new enough to be a flat screen, digital set (as opposed to a CRT analog type), that's virtually certain (remote signals have become more standardized in the HD era).