I would like to point to my own timeline (sigged below), specifically pages 23 through 26.
While the earlier the PoD the better, there are a handful of "late" ones that can easily work. You can go for one right at the start of independence, and switch the Insurgent leadership from Hidalgo to Ignacio Allende. Hidalgo was a charismatic orator that held a lot of influence among the indios, but as a parish priest he didn't have much military experience. If you want the revolution to be led by an actual soldier, Allende is the way to go. Have the insurgents win more battles early on and prevent their ill fated trek north, then that same leadership may stick around to clean up Mexico post-independence. This is the PoD I utilized for my TL, but it's far from the only one.
If you have a later PoD you can go for Iturbide retaining his crown and the empire endures. As long as Iturbide doesn't antagonize congress too much, he can manage the first few years before Mexico can focus on preparing for the eventual confrontation with the US. Conversely if you'd rather not do with the Empire and prefer a republic, you can try preventing the coup of 1829 from ever happening. Ensure Manuel Gómez Pedraza assumes power instead of Guerrero and the precedent of a peaceful transition of power via election isn't smothered in the crib.
Whichever way you go, Mexico needs to spend at least the 1830's or so preparing for the war. Better weaponry would do wonders for the Mexicans, as well as focusing on building a navy with some actual muscle. Reforming the Army would probably be best, but that might be tricky. By the time the war breaks out in the 1840's the US is in for a long and bloody war. Mexico just has to play the defensive and wear the Americans out.
I will also stress that any Mexican victory will require that the Mexicans cooperate with the Comanche. Also, Santa Anna must be dealt with somehow. Either keep him from attaining any significant power or just kill him off. Never underestimate that man's ability to fuck everything up.