Just to be clear, getting more votes doesn't mean you win the presidency. You have to win the electoral college.
> Does that immediately free him from prison
No.
> or would he need to formally pardon himself first?
He would need to pardon himself.
Just to add, a president can only pardon federal convictions, not state convictions. Debs was convicted of federal charges though so he would have been able to pardon himself.
> Could he even do that?
There has been debate over the last couple of years and no answer has been agreed upon, though it likely is due to the current situation. The only way is for a president to try it.
From the Constitution:
Article II, Section 2, Clause 1:
> The President shall be Commander in Chief of the Army and Navy of the United States, and of the Militia of the several States, when called into the actual Service of the United States; he may require the Opinion, in writing, of the principal Officer in each of the executive Departments, upon any Subject relating to the Duties of their respective Offices, and he shall have Power to grant Reprieves and Pardons for Offences against the United States, except in Cases of Impeachment.
Ultimately the Constitution does not state that a president cannot pardon himself so as long as it is not for impeachment he probably could, but I'm not a lawyer so take my opinion with a grain of salt.
I.e. Debs yes, Trump no.