The Gemara (Chagiga 3b) discusses this very question:
אלו תלמידי חכמים שיושבין אסופות אסופות ועוסקין בתורה הללו מטמאין והללו
מטהרין הללו אוסרין והללו מתירין הללו פוסלין והללו מכשירין שמא יאמר אדם
היאך אני למד תורה מעתה תלמוד לומר כולם נתנו מרועה אחד אל אחד נתנן פרנס
אחד אמרן מפי אדון כל המעשים ברוך הוא דכתיב (שמות כ, א) וידבר אלהים את
כל הדברים האלה אף אתה עשה אזניך כאפרכסת וקנה לך לב מבין לשמוע את דברי
מטמאים ואת דברי מטהרים את דברי אוסרין ואת דברי מתירין את דברי פוסלין
ואת דברי מכשירין
(Loose translation) Lest one say: How can I study Torah when it contains so many different opinions? The verse states that they are all “given from one shepherd.” One God gave them, One leader said them from the mouth of the Master of all creation etc. You too; make your ears like a funnel and acquire for yourself an understanding heart to hear the opinions of those who rule things to be ritually impure and the opinion of those who rule them pure; the opinion of those who prohibit and the opinion of those who permit.
The Gemara (Avoida Zara 7a) brings a machlokes on what to do when faced with a dispute in practical halacha:
היו שנים אחד מטמא ואחד מטהר אחד אוסר ואחד מתיר: אם היה אחד מהם גדול
מחבירו בחכמה ובמנין הלך אחריו, ואם לאו הלך אחר המחמיר. ר' יהושע בן
קרחה אומר בשל תורה הלך אחר המחמיר בשל סופרים הלך אחר המיקל
If there are two opinions - one rules it is pure, the other tamei; one forbids and the other permitts: [The opinion of the Tanna Kama] If one of them is greater in wisdom or number, follow him. If not, follow the more stingent position. R' Yehoshua ben Korcha said: Regarding Biblical Prohibitions, follow the stringent position. Regarding Rabbinical prohibitions, follow the lenient opinion.
When faced with two dissenting opinions, one does not have the right to choose the position he prefers (at least when applicable to Biblical prohibitions). [We pasken like R' Yehoshua b Korcha - see YD 242 with Shach]
The Ritva qualifies this:
והוי יודע דכי אמרינן הלך אחר המחמיר, היינו לדידן דכיון דספיקא הוא
נקטינן בספקא דאוריתא לחומרא אבל לדידהו גופייהו ודאי כיון דשקולין נינהו
וכל אחד עומד בשמועתו זה נוהג כדבריו אפילו לקולא וזה נוהג כדבריו והכי
מוכח ביבמות פרק קמא ודאמר נמי דאחרים הבאין לעשות בהוראתן הולכין אחר
המחמיר בדאורייתא דוקא בענין אחר כיוצא בזה שנחלקו אלו אבל באותה חתיכה
עצמה שנחלקו בה כיון דשקולין הם וכי הדרי איפליגו בה אין הוראת איסור חל
באותה חתיכה והכי מוכח התם ביבמות דאמרינן התם דבית הילל ובית שמאי אלו
עושין כדבריהם ואלו עושין כדבריהם והיו מתירין צרת הבת לאחין והיתה מותרת
לינשא להם שעל כל אחד ואחד שהיה מעשה בא עליה היו מורין לה בה להיתר ואלו
לא היה לזה לעשות בהוראתם כנגד דב"ה לא היו מורין בה להיתר אלא ודאי שמע
מינה שאותה אשה מותרת היתה לינשא על פיהן׳ – כלומר שאע״פ שבעלמא צריך
לחשוש לדברי המחמיר לגבי דיני דאורייתא, היכא ששמע פסק מפי המיקל הרי זה
מותר לגבי חתיכה אחת, ומותרת לו להקל לכתחילה
The Ritva makes two important points:
(a) This ruling is only to us (students) who don't have an opinion of our own; the one who presents the lenient position himself may continue to follow his own opinion and need not submit to the stringent position [even regarding Biblical prohibitions];
(b) One who recieves a lenient ruling directly from the lenient posek may follow that position regarding that specific scenario; only in subsequent similar shailos must he defer to the stringent ruling.
The Chazon Ish (YD 150.5) adds another factor - one who chooses a Rabbi for himself, and follows his rulings on all halachic matters may be lenient for his opinion even when faced with a stringent dissenting view. (Like talmidei Beis Shamai could follow Beis Shammai).
In summary:
(a) If you are confident in your own opinion [provided you are qualified to have an opinion], you may follow your own conclusions.
(b) If you have a specific Rabbi whose opinion you follow in all halachic matters, you may follow his opinion,
(c) If you recieve a ruling from a specific posek, you may follow his ruling even when faced with dissenting stringent views,
(d) If you do not have your own opinion, your own Rabbi or a specific Psak, you must follow the stringent ruling (when relative to Biblical commandments).