He's in the burning building because he planned the whole thing. As the final stages of his plan proceeded as intended, he wrestled with his own self doubt about seeing it through. But ultimately, House gives up his life to spend the rest of his best friend's with him, and then to move on and find some new life away from the surroundings that would inevitably lead him back to his self-destructive ways. House finally succeeds in "destroying" himself, but without actually destroying
himself and being relegated to eternal boring nothingness. He finally solves the puzzle of how to change and move on to a different kind of life.
Alternatively, House and Wilson both die and go to heaven!