There is absolutely no way that a high school teaching job pays more than a research chemist. It's pretty apparent that he had a falling out of some kind, probably over Gretchen. Whether it was entirely his fault is left to our imaginations, but after he threatens them in the finale he does say "This is a way to make it right." as he leaves.
There were two parts to the falling out.
1. Gretchen was his lab assistant and Elliot was his co-worker. The three of them founded Grey Matter while working at Los Alamos, which is near Santa Fe. At some point Walt feels insulted by Gretchen's family, and decides to leave Grey Matter. He takes a $5k buyout offer. 20 years later, Grey Matter is part of the nobel prize win, a public company, and worth $2 billion dollars (as founders Gretchen and Elliot would be worth in the $300-500m range), and Walt has respun the past so that Gretchen cheated on him and conspired with Elliot to steal his share of the company, none of which is probably true.
2. He is working afterwards as a lab assistant at Los Alamos, and starts dating Skyler who works at a restaurant near Los Alamos. She gets pregnant, they marry and buy a small house in ABQ. This happens during the flashback to them buying their house - Walt is still working at Los Alamos, he still has big plans for the future. Sometime after this he quits or is fired from Los Alamos (probably his pride, again) and he takes a teaching job at an ABQ high school to temporarily fund the bills. He ends up staying at the job - this is a common theme, marriage and children "sap" your career.
btw, both Microsoft and Apple had early employees/founders who sold their initial shares for $5-10k, and each would have been worth billions if they had kept it for 20 years. So the situation is far from unrealistic.
I think a good flashback would have been to the time when Walt leaves Grey Matter, we would have Gretchen's dad make some silly comment ("treat my baby right, she grew up a princess and isn't used to living like you!") and Walt just goes insane and takes it out of proportion and context. I guess there just wasn't enough time, and it might have been too confusing or not central to the storyline.