"Which" is more formal when asking a question that requires a choice between a number of items. You can use "What" if you want, though.
Generally speaking, you can replace the usage of "which" with "what" and be OK grammatically. It doesn't always work the other way around, however. There needs to be a context of choice.
i.e. What do you want to eat? Which 'food' do you want to eat?
What (of all colors exist) is your favorite color? Which (of the shown colors) is your favorite color?