Both "what" and "which" are relative and interrogative pronouns. Sometimes they are very close in meaning, eg you could say "What colour/ which colour do you like best?"
Usually, though, "what" in a question suggests unlimited possibilities, eg "What do you like doing?" - the answer could be almost anything. "Which do you like?" on the other hand, shows a definite, limited list of alternatives (basketball or tennis, say.)
As relative pronouns, they are quite different. "What" again means unlimited possibilities: "She asked what my name was," " I don't know what to do." "Which" is specific: "I live in the countryside, which is very pleasant," or "I don't know which jacket to buy."
"What" is used in a range of expressions, all giving this idea of "no limits:" "What about...?" "What if..?" or used as a substitute for any other word: "I saw whatshisname this morning" or "I bought a whatyoucallit."