If a well loved politician wanted to stay in power, how could they do it legally

Here’s my thought:

First, create a cabinet-level position for yourself. Grand High Poobah or whatever.

Second, establish informal rules that give virtually all power to use. The President can announce your nominations for court positions, but he just rubber-stamps what you do. Stack the courts, the cabinet and the Congress with your cronies.

Third, modify election laws to ensure that your party controls everything in perpetuity. You probably want a good dictator-style election where your party beats your opponent with 95% approvals.

Once you have a stranglehold, any time someone disagrees with you, remove them. Even the President can be removed either by the Cabinet or the Congress. “You disagree with ME?! That’s both treason and insanity! Start packing.” It won’t take long until the public stops looking to the President as a source of power and learns that only Grand High Poobah matters.

It might be hard to obtain this level of control, especially with the Supreme Court serving long non-elected terms and with states retaining so much independent power, but once you have the control, checks and balances are just words.