Sometimes they are interchangable, sometimes one sounds better than the other.

Generally,
пытаться - to try, to make an attempt to do something
стараться - to try, to do your best or to make an effort to do it in a certain way

eg.
Я стараюсь быть вежливым со всеми, кого встречаю ~ I do my best to be polite to everyone I meet
Я пытаюсь быть вежливым со всеми, кого встречаю ~ I try to be polite to everyone I meet (but I probably fail)