This confusion is easy to resolve once you understand that Spanish is an inflected language, so verbs are marked (that is, changed) to reflect things like tense, person, and number. (See Wikipedia: Spanish Grammar.)
Describing all of the different types of inflections and verb changes is a lengthy process and beyond the scope of a single answer, so I'll try to focus on just what is concerning you at the moment.
The difference between "tengo" and "tienes" arises from a difference of person: "tengo" is in the first person, and "tienes" is in the second. The difference can be understood best by an example:
Yo tengo anteojos de sol. (I have sunglasses.)
vs.
Tú tienes anteojos de sol. (You have sunglasses.)
A complete conjugation of the verb "tener" would be as follows:
Person / Number |
Conjugation |
First person singular |
yo tengo |
Second person singular (informal) |
tú tienes |
Second person singular (formal) |
usted tiene |
Third person singular |
él/ella tiene |
First person plural |
nosotros/nosotras tenemos |
Second person plural |
vosotros tenéis |
Second person plural (formal) |
ustedes tienen |
Third person plural |
ellos/ellas tienen |
That should be enough to get you started; you'll just need to figure out what person the subject of the sentence is in, and choose the appropriate form. :) That said, you'll definitely want to look into the subject of inflection more, since it's a real must if you want to be able to speak Spanish to any degree (You can learn a lot of verb classifications and rules that will make this easier.)
As for the second point of why "yo" was used in some cases, and not in others, the thing is that since Spanish verbs are inflected to show person (and number), subject pronouns (like "yo", "tú", etc.) can be omitted without making the sentence any harder to comprehend. Unless you want to be very formal, add emphasis, or an ambiguity might arise, feel free to omit pronouns.
Hope this helps. :)