Basically I would agree that a shift in internal politics in both would be the best chance of retaining their more or less undamaged empires, although not going to war at all would be helpfull as well.
For Germany, the point of no return would be in the early 30's , when the National Socialist Movement came to power and abbandonet democracy. If this would not happen the way it did, meaning the NSDAP would fade away eventually, soon after its victory in 1932 elections, the German Reich would more or less be continuing as it was in the prewar (prior to 1939) form. A more center Right government of Democrats of liberal and christian origin would take over after the elections held in 1933/1934, since after this, the NSDAP in the OTL put aside the other political parties. In the start it could well include the remnants of the NSDAP as well, but with a Christian Democrate as Chanclor, since the NSDAP would become smaller than the CDU/CHU forerunner, as in the OTL actualle happeded to be the case in this timeframe. The crucial point would be to allow the SDP to retain its seats in the Reichstag, as it in the OTL was ruled out, simmialr to the Communists.
Japan would be more difficult to maintain as an Militaristic Empire. Propably the key would be to have not the Army, but the Navy take over politics, as the Army was not the most peaceloving instrument in Japan. The more conservative Navy was, which could mean it would seek contact with the foreign states more easily by diplomnatic means, than by arms. With a Yamamoto, or Nagano in place of the warmaking Tojo in the prime minister role, the Japanese would likely be more willing to seek out more peacefull means to negotiate a deal of some kind in times of conflict.