My understanding and this has of course never been tested is that if elected president while in prison, he would be let out as long as he is president. Of course trump would become a president for life as he's obviously a wannabe dictator so that would take care of it.
Also the new president if not him could pardon him like Nixon was pardoned.