How to switch X windows from the command-line?
Sounds like you're looking for wmctrl - see here for more examples.
Edit: Your window manager/desktop environment has to be standards compliant (EWMH). And here are more examples.
In cases where sr_'s solution does not work, you can also try xautomation. One of the tools included in that package is xte
(see manpage) - it simulates keystrokes, mouse movement and more. Here's how you can use it to simulate Alt+Tab:
xte "keydown Alt_L" "key Tab" "keyup Alt_L"