Hello!
Both of your sentence is perfectly correct.
But these are really interesting,and very difficult to explain.Because the both of question 1and 2are very similar to with each other.
Q1 is focused on "who is".
Q2 is focused on "the name of occupation".
I think...
1)Q:"どなたが "先生ですか?
When you ask me"どなたーが ",
↓A voices in my head
どなたが…OK!I should start finding the name of person who is working as a teacher…
Mr.Yamamoto…,no,he is a police officer.Ms.Brown…,no,she is a president of a firm.So,who is…Oh! I remember that Mr.Tanaka! "He!" is a teacher.(not the other person)
my answer will be :田中さん(が先生)です。
→"Mr.Tanaka!" is a teacher.(contain the meaning of"Mr.Yamamoto,and Ms.Brown are not")
2)Q:"先生は"どなたですか?
When you ask me"先生ーは ",
↓A voices in my head
先生は…OK!The main theme of this conversation is "a teacher".I remember the occupation of them.Well…A police officer is Mr.Yamamoto,A president is Ms.Brown,A teacher is…Mr.Tanaka.(when you ask"先生は",firstly,I pay more attention to the occupation of them.)
my answer will be :(先生は)田中さんです。
→"A teacher! "is Mr.Tanaka.(contain the meaning"the other persons are a police officer and a president")