Practice these commands when he's calm, and in time he should learn to stop barking at your command, even when he wants to bark at something.
A tired dog is a quiet dog.
If your dog barks when alone, tire him out before you go.
Take a long walk or run, play ball or take a trip to the dog park before leaving.