Prevent windows and Desktop icons from rearranging with multiple monitors?
Disconnecting the external display should not affect the positioning of windows and icons that are not on the external display, unless you have it set as your primary display. To set the internal display as primary, go to System Preferences → Displays → Arrangement and drag the menu-bar image (the white stripe) to the internal display. This will, of course, cause the menu bar and Dock (unless your secondary display is below your primary display) to be on the internal display.
For a window that is positioned on a secondary display, if you minimize the window to the Dock or hide its application before disconnecting, and reconnect before making it visible again, then the position of that window will be preserved. I find this quite useful.