I Am Legend is a lot of things in one. First of all, it's the story of loneliness, very similar to Cast Away in this regard, dealing with a protagonist whose constant and unrelenting isolation is held in tension with his will to live and his struggle for hope. Also, it's a horror film, largely designed to unnerve the audience.
Let's deal with the horror aspect, because it's the most academically important feature of the story, since this film is a retelling of the novel by the same name which help to start the zombie story (although technically, they were originally thought of more like vampires).
Zombies represent an anti-resurrection from the dead, so before anything else is said, the first important feature is that it goes directly against the Christian narrative of a divine resurrection. This is not to say the novel is anti-religious, because religious themes are introduced throughout the film (taking care of neighbors and strangers, holding on to hope in spite of grim, deathly circumstances, becoming the Christ-character for the salvation of others—all these themes are well-represented in the story). So the horror element is not the absence of meaning, it's just the introduction of terrifying possibilities.
By focusing the audiences attention on fear and darkness (like the scene where the man chases his dog into a dark, zombie-infested parking garage), the film asks the viewer to reconsider their assumptions about life. By causing actual fear, the mind is forced to acknowledge that the sense of safety that undergirds daily life might actually be unfounded or wrong, and maybe the truth is closer to terror than we formerly imagined. In other words, scaring the viewer provides a cathartic release of all our daily fears that we ignore in the pursuit of happiness, to quote another of Will Smith's films.
Eventually, though, the plot resolves with Christian overtones. In either ending, the implication is that the survival instincts did not go to waste, but were there for the benefit of others. The sacrifical death in both cases is unignorably hopeful.