For me, the fly is a manifestation of the beginnings of the crack in Walt's moral character. Walt's monologue is especially telling of this internal conflict he's experiencing, which has been beautifully propelled thus far throughout the show and launches his character into new and scary territories henceforth.
In the beginning of the episode, the presence of the fly in the lab contrasts with Walt's obsessiveness and quest for perfection, illuminating the very core of his character. Walt is a "good" person, straight-edge, moral, trying to do the right thing. The dedication to cleanliness and order in the lab, adding up (at least trying to, thanks to Jesse's skimming off the top) the numbers for the yields they produce, these rituals for accuracy and correctness imply not only how little margin for error Walt gives himself as a person (and now his employer) but also how carefully constructed Walt's plan for his family has been this whole time. Walt didn't enter this line of work on a whim. His actions and decisions have been deliberate and thoughtful, all with the intention of providing for his family when the time came that he would be gone.
But now, "there's no end in sight," as Walt states in response to Jesse's concern about Walt's health.*** Walt reassures him that his cancer is still in remission, and therefore there's no end in sight. This remark, however, speaks more to Walt's inner turmoil rather than his health prognosis. Here lies the crux of the matter: Walt has turned to cooking meth for a "good" and "moral" purpose, to take care of his family. What more can a good man do in his life than provide for his wife and children, especially after he's gone? However, with no end in sight, there's now a "fly in the ointment," a contaminant in the laboratory of Walt's own experimentation. His well-laid plans are suddenly tainted; they've outgrown their usefulness; the perfectionist's plans are no longer perfect. Walt is still alive, cooking meth, and for what? To what end do his plans bring him and his family?
Jane's death opens up Walt's psyche to the fact that perfection no longer exists. The circumstances of life took care of that. How perfectly did life arrange for Walt to be at Jesse's house at that exact moment in time? How perfectly did life arrange for Walt to meet Jane's father at that bar that night? Walt's monologue of going back and forth, justifying and validating decisions, ruminating on past actions and possibilities, especially the odds of meeting Jane's dad at that bar that night, is essentially the fly buzzing in his brain. Here his inevitable turn towards immorality, Walt mentally comes to grips with what he's done and what his plans have become:
"There's been a contamination."
What's more, killing the fly, getting rid of the contaminant, perfecting the imperfection, is of no use. Walt's character has turned a corner. He realizes this when he gives up on the fly in his drug-induced state, and when the fly reappears in the middle of the night at the end of the episode. From here on out, what happens to Walt and Jesse now depends entirely on different sets of circumstances.
***Jesse's concern for Walt's health is illustrated in his story about his aunt and the possum. Jesse tells this story as a demonstration of his concern for Walt's cancer returning. As Jesse stated in his story, his aunt was "obsessive" and "mad" about the possum scurrying underneath the house, even after they got rid of it. "It wasn't like her to be that way," but they realized it was because the cancer had come back and spread to her brain. Once they figured this out, they got her treatment and "she was a lot happier."
More questions on Breaking Bad (TV Series):