With the commands
xrandr --output VGA-0 --auto
xrandr --output LVDS --off
The screen automatically transfers to the external display. It doesn't even need sudo powers. To find out the name of the displays just do:
xrandr -q
Which should give something like:
VGA-0 connected 1280x1024+0+0 (normal left inverted right x axis y axis) 338mm x 270mm
...
LVDS connected (normal left inverted right x axis y axis)
...
Extending the displays can probably be achieved in a similar manner.