To get the Second Mexican Empire to survive you need a few things to happen. Firstly Max needs to be seated more sec;urely on the throne (an actual Imperial government being established, and a real army being set up, not the half measures the French took OTL). Secondly the French actually have to engage in more nation building, rather than just looting the country for cash. Thirdly, the United States cannot intervene.
Historically in 1864-65 Juarez was on the ropes, controlling only the remote parts of Mexico and being unable to engage the French in open battle. He was very close to losing in 1865 until the United States started sending him cash and weapons, and making their displeasure known. The use of the American border as a shield protected Juarez and allowed his forces to outflank the Franco-Imperial forces in the north, and drive them south.
Another big problem is that the French essentially left Max to his own devices, and Bazaine tended to undermine the Mexican court at every opportunity in furtherance of his own objectives. He never really worked to create a Mexican Army Max could count on, and only did so at near the last possible minute. Essentially leaving Max with no one who could protect him or his rule and no opportunity to further his support in the country.
Max, was also not a good administrator. As a public figure people could certainly like him, but he was out of his depth when it came to running a government. I've read Carlota had a bit of a better grasp on practical matters, but her sex really prevented her from making any impact, and the men who Max appointed as administrators and advisers spent more time back biting and currying favor with the Emperor rather than dealing with the practical matters of state.
If Max had more time to establish his rule he might have been able to hold on.
Juarez though, would have to die. He was the rallying point for the Liberal cause as the elected president, his death would be demoralizing, and his commitment to the Republic was the strongest. While most Mexicans would have held their nose at working with the French and their foreign puppets, they would most likely have engaged in negotiations some time in 1866 had Juarez been killed in 64-65 as he would be hard to replace, and without any substantial foreign aid they would be running low on the means to continue resistance.