Train travel in Germany is very easy. There will be a connection that will take you right to either airport. Munich is closer. What is the timing? You will likely have to spend the night if you have a flight leaving in the morning. Will add times and links in a bit.
ETA: looks like about 2 hours to Munich airport. about 30 euros. And just under 3 hours to Frankfurt airport for about the same price. One change to Munich (central station) no changes to Frankfurt. Trains leave pretty often.
https://www.bahn.com/en is the website, easy to navigate.