the boy's family was probably a casualty of the war.
I'm fuzzy on how the machine first makes contact with the boy.  I do remember that the boy stays with it, and the robot assumes the role of preparing him to carry out the task it cannot.  It educates the boy, protects him as he sleeps under it, and IIRC, instills a sense of duty in the boy for the task.
The machine trains and protects the boy for many months, probably two or three years.  As the story proceeds, the machine becomes weaker and weaker. As its power cells drain, it loses the ability to move, relies on solar energy to extend its life, and begins to corrode from the expose to salty sea air. It eventually shuts down completely, completely without power.
The story closes with the boy, now a teenager, and well-educated, taking the bundle of dog tags from the machine, and leaving the beach.  He has taken up the task of returning the dog tags, carrying on the work of the machine.
Timeframe of Publication
I'd say this one came out no earlier than the 2000's.  It may even be as recent as the 2010's.  I read it in a mainstream sci-fi magazine, like Analog or the like (can't remember which one, unfortunately).

A:

Tideline by Elizabeth Bear.

The story follows a sentient war machine, Chalcedony, which is the
  lone survivor of a previous and highly apocalyptic war that has
  reduced the human population virtually to cavemen and hunter
  gatherers.