There is a very different dynamic between student and teacher than there is between two colleagues, even colleagues occupying different places in the hierarchy. You need to see yourself as having two separate identities in relation to this teacher.
While you are in the role of a student, you should speak as a student. This is especially important if you are in the company of other students.
You need to decide the point when you are stepping out of the role of student and into the role of colleague and ensure that it matches or follows the point at which your teacher has shed their role.
There may be subtle indicators that the teacher has shed their role. How they speak to you, how they address you, and their general demeanor might be more or less subtle clues.
All of this might, however, be of no special importance to your particular teacher. Some people tend to be more or less concerned about what is considered 'proper etiquette' and part of your job is to gauge your teacher's position and if you can't, to err on the side of propriety.
Long story short, when you're in the classroom or in the presence of other students immediately before/after class, ありがとうございました would likely be more appropriate.