Where does arduino IDE store the latest board selection?
It is stored in preferences.txt in your Arduino data folder. 

You can find more about that file, including where to find it, here.

Some of the keys you may be interested in are:


board=uno
serial.port=COM3
serial.debug_rate=115200


However maybe for your workflow the Arduino IDE isn't the best tool for the job.  You may consider arduino-builder, which is the back-end that the Arduino IDE uses to do the actual compiling, or maybe another IDE entirely, such as PlatformIO or UECIDE.