Which is a choice between things. So you are in a shop and there are three sandwiches in front of you, "which do you want?" asks the server.
What is just a general open question. So you walk into a shop and they ask have no idea why you are there, "what do you want?" asks the server. The server has no clue so she is asking the most open question that makes any sense.