Loïc answered for the main monitor question.
For closing the lid of your MacBook, it's what is called to use it in clamshell mode. As you will have to have an external mouse and keyboard connected to your laptop, you have to boot, close your lid (your mac will turn to sleep) and then use your mouse or keyboard to wake it from sleep mode.
If you have a bluetooth mouse and/or keyboard, you have to go in the bluetooth prefpane, and, in Advanced settings, check the
Allow Bluetooth devices to wake this computer.
By the way, in this situation, no need anymore for a main and secondary monitor :)
When you open your lid while using only the external monitor, the macbook screen will stay black. If you want to use again both screens, you have to go to the Displays prefpane and click on
Detect displays. Or, like me, check the
Show displays in menu barand use the menubar instead to detect the displays.