If the batteries are original, odds are that is the issue.
Other possibilities include cellphone interference (mentioned above), or interference from some other source of radio frequencies nearby. If you are in a place that you visit frequently, or at home, and if the key normally has worked at that location with no issues, I would focus on the battery.
Note that the owner's manual has two work-arounds for poor reception: One is to place the key near the internal antenna, by putting it into the center console cup holder, or right below the 12-volt power outlet.
If you are outside the car and cannot unlock it, the manual suggests this procedure:
"
To unlock Model S (and disable the security
alarm), first position the key near the base of
the passenger side windshield wiper, as
shown. Then press the front passenger door
handle. If Model S doesn't unlock, try adjusting
the position of the key. The key must be in the
correct position."
It is useful to know these techniques for future possible need, even if your present problem is just the need for a new battery!
Good luck.