It is obligatory for one who has reached the age of obligation (“religious puberty” or “bulugh”) to choose the most learned marja and follow his fatwas or verdicts. There are only three ways one can identify the most learned of marjas:
a) If one is certain that a particular marja is the most learned.
b) When two persons who have the ability of identifying the most learned, confirm [shahadah/testimony] that one is so.
c) When a group of learned scholars confirm such a matter.
Now, if one identifies the most learned through one of the abovementioned and follows him for a while, then doubts about the marja and following him, his past taqlid is valid and in other words all of his actions and worship he/she has done according to the marja’s views are valid, but he/she has to choose a marja he/she is sure about from then on and for future actions and worship. To do so, he/she has to do further research; if he/she becomes certain that the marja can no longer be followed, he/she must switch to a qualified marja and all of his/her past actions are valid (given that he/she had chosen the previous marja through one of the three methods mentioned above).
When one embraces a religion, he has accepted the laws and rules of that religion as well and needs to act upon them. Islam is no exception. We the Shia believe that Prophet Muhammad (pbuh) has brought these laws to us and they have been expanded by the imams (as) and during the occultation of Imam Mahdi (as), their further expansion is the responsibility of the imam’s (as) “general” representatives [the imam (as) has both “specific” and “general” representatives; the specific ones being the four whom he had specifically appointed, the last one passing away in the third century (ah), and the general ones being qualified mujtahids who are experts in this field].
There are three ways for identifying a mujtahid or distinguishing the most learned of them:
1- When a person is certain that a particular person is the most learned one, eg. by asking other learned individuals, or in the case that the person himself is a learned one, able to identify the most learned without anyone’s help.
2- When two persons, who are learned and just and possess the capacity to identify the most learned, confirm that a person is the most learned, provided that two other learned and just persons do not contradict them.
3- When a number of learned persons who possess the capacity to identify the most learned, certify that a particular person is the most learned, and one becomes sure from their saying that that person is the most learned [note that there is a difference between this method and the previous one; here what is important is for the person to become sure, while in the previous, the criterion is for two just witnesses to “testify” [shahadah/confirm] to that person that a certain mujtahid is the most learned, regardless of whether one becomes sure from their saying or not, all that is needed is for them to be “just”, meaning that they have be to pious individuals who perform their wajib acts and refrain from sins and haram
The first way is contingent upon one knowing the different conditions that need to be met by a mujtahid in order to be qualified for being followed by others:
1) Being a mujtahid
2) Being baligh (meaning that he has to have reached the age of obligation or “religious puberty”)
3) Being male
4) Being of legitimate birth
6) “Idalah” or “justice”
7) Being alive [therefore one can't follow a dead mujtahid from the start]
8) Being a twelve-imam Shia [Ithna Ashari]
9) According to obligatory precaution, he has to be the most learned and also one who isn't ravenous for wordly desires. 
Of course, if one wishes to use the second method (two just persons) for identifying a mujtahid, he has to be sure that the two are both just and are learned enough to do so.
Also, if one uses the third method, he has to go to religious scholars and experts. It is on this basis that The Seminary of Qom has introduced an elite group of mujtahids who are all qualified for being followed in which have been listed below in Arabic/Persian alphabetical order:
1-The Grand Ayatullah Bahjat
2- The Grand Ayatullah Sayyid Kadhim Ha’iri
3- The Grand Ayatullah Sayyid Ali Khamenei
4- The Grand Ayatullah Sayyid Ali Sistani
5- The Grand Ayatullah Sayyid Musa Shubairi Zanjani
6- The Grand Ayatullah Lutfullah
7- The Grand Ayatullah Nasir Makarem Shirazi
8- The Grand Ayatullah Husein Vahid Khorasani
Any Muslim who chooses any of these mujtahids as his/her marja and acts according to his fatwas has surely fulfilled his/her religious responsibilities and duties. 
Now sometimes it happens that after one chooses a marja using one of the abovementioned ways, he doubts about his taqlid and that if his marja was actually qualified or not? What needs to be done now and what happens to his past actions/worships he has done according to the views of the marja all need to be clarified, but first we must say that if one identifies the most learned marja using one of the ways introduced by religion itself [which were mentioned above], this “religious proof” [the way religion has introduced] is valid and reliable until another religious proof that contradicts it comes up [and this doesn’t mean that we have to go looking for religious proof that contradicts it and make sure there is none, what is meant is that it is valid as long as nothing else has come up), even if the religious proof used doesn’t give us surety [for instance, when one asks two just and learned persons to confirm and “testify” to the qualification of a particular marja, and they do so, there are still chances that they are mistaken and that the marja isn't actually qualified, so their confirmation doesn’t grant one surety, yet since religion has acknowledged this method, it can be utilized]. 
In cases that one doubts about the qualification of his marja after following him for a while, Islamic jurisprudents have said: “If one doubts about the qualification of his marja from the beginning [and that he should have been followed at all], he/she has to do more research [and find one who he/she is sure about]  , meaning that he/she has to practice valid taqlid from then on for present and future actions, but his/her past actions are all valid.  In other words, after investigating, if one realizes that his/her taqlid had been wrong the whole time, he/she has to switch to another qualified marja  , meaning switching from an unqualified marja that has mistakenly been followed for some time and now is known to be unqualified, to a qualified one is wajib  , yet his/her past actions are all correct if the marja had been chosen through “religious proof”  .
Conversely, if one chooses a marja not using one of the ways religion has introduced and acts according to his judgments, and later on decides to change, his past actions are only correct and don’t have to be made up if they comply with the verdicts of a qualified marja.
In response to this question, the Grand Ayatullah Khamenei says: “Taqlid that has been practiced not based on religious standards is void, unless it complies with the verdicts of a marja that is qualified and needs to be followed now.
 Tawdihul-Masael (footnotes by Imam Khomeini), vol.1, pg.15. Of course what is meant by two learned people, is learned in the field of Islam and religion.
 Mohammad Husein Fallahzadeh, Amuzeshe Fiqh, pg.27.
 Ajwibatul-Istifta’at (farsi), pg.6, question 27.
 In his commentary on Urwatul-Wuthqa, vol.1, pg.36, under issue 42 (إذا قلّد مجتهداً، ثمّ شکّ فی أنّه جامع للشرائط أم لا، وجب علیه الفحص), Imam Khomeini says: “على الأحوط فی الشکّ الساری، و أمّا مع الشکّ فی بقاء الشرائط فلا یجب” and Ayatullah Khu’i says: “إذا قلد مجتهدا، ثم شک فی أنه کان جامعا للشرائط أم لا، وجب علیه الفحص” Minhajul-Salehin (of Ayatullah Khu’i), vol.1, The Complete Software of the Fiqh of the Ahlul-Bayt.
 Ayatullah Makarem Shirazi: See Tawdihul-Masael (commentary of Imam Khomeini), vol.1, pg.27. Also see: Imam Khomeini, Tahriul-Wasilah, vol.1, pg.10, issue 25 (إذا کان أعماله السابقة مع التقلید و لا یعلم أنها کانت عن تقلید صحیح أم فاسد یبنی على الصحة) and Ibid, issue 26 (إذا مضت مدة من بلوغه و شک بعد ذلک فی أن أعماله کانت عن تقلید صحیح أم لا، یجوز له البناء على الصحة فی أعماله السابقة و فی اللاحقة یجب علیه التصحیح فعلا), and: Ayatullah Khu’i, Al-Ijtihad wal-Taqlid, issue 41 (إذا علم أن أعماله السابقة کانت مع التقلید لکن لا یعلم أنها کانت عن تقلید صحیح أم لا بنى على الصحة), The Complete Software of the Fiqh of the Ahlul-Bayt.
 It is also noteworthy to say that according to Imam Khomeini, switching between marjas has various cases in which each case has its own ruling:
- Switching from the less learned to the most learned: it is wajib as an obligatory precaution.
- Switching from one marja to another, while both are equal in learnedness:
- Switching from the most learned to the less learned: Impermissible.
- Switching from a marja that one has followed for a while and now it has turned out that he wasn’t qualified for being followed: Wajib.
- Switching from a marja who was qualified in the beginning, but has lost one or some of the conditions such as being sane, to a qualified marja: Wajib.
- Switching from a dead marja whom one used to follow to a live one: Permissible and Ihtiyat Mustahabb (preferred precaution).
 Amuzesh Fiqh , Muhammad Husein Fallahzadeh, pg.29.
 Of course some Islamic jurisprudents believe that in all cases, one must compare his actions with the verdicts of the qualified marja, if they match, nothing needs to be made up, but if they don’t, they have to be made up, regardless of whether the previous marja had been chosen through religious proof or not. For instance, Ayatullah Khu’i says: “إذا قلد مجتهدا، ثم شک فی أنه کان جامعا للشرائط أم لا، وجب علیه الفحص، فإن تبین له أنه جامع للشرائط بقی على تقلیده، و إن تبین أنه فاقد لها، أو لم یتبین له شیء عدل إلى غیره، و أما أعماله السابقة فإن عرف کیفیتها رجع فی الاجتزاء بها إلى المجتهد الجامع للشرائط و إن لم یعرف کیفیتها قیل بنى على الصحة و لکن فیه إشکال بل منع، نعم إذا کان الشک فی خارج الوقت لم یجب القضاء” Minhajul-Salehin (of Ayatullah Khui), vol.1, pg. 7