The reasons Roy Batty saved Deckard are already covered in another question. As to why he murders Tyrell and Sebastian, it's not explicit, but I think it's possible to infer from context. Batty, as has been mentioned in other answers, is a combat model. His brain is in some sense hard wired to solve problems by killing. However, we know that he can break his programming - after all, he's also programmed to follow orders, and that's not working out too well. It does seem reasonable to assume that given multiple choices to solve problems, killing will be one of the options that would naturally occur to him.
So, what problem is he trying to solve? The androids are dying, and they know they are dying. They come to Earth, despite the knowledge that they will be hunted if they do so, in order to address this problem. They succeed in finding the one man who might be able to help them, and he tells them that he can do nothing. Batty is Tyrell's creation, and that creation is flawed. Consider the dialogue leading up to Tyrell's death:
Tyrell: But, uh, this-- all of this is academic. You were made as well as we could make you.
Roy: But not to last.
Tyrell: The light that burns twice as bright burns half as long. And you have burned so very very brightly, Roy. Look at you. You're the prodigal son. You're quite a prize!
Roy: I've done questionable things.
Tyrell: Also extraordinary things. Revel in your time.
Roy: Nothing the god of biomechanics wouldn't let you in heaven for.
So, Batty has just found out that his creator is flawed, and that he will die because of this. Tyrell's pride at his own creation is nonetheless clear, and aludes to Tyrell's own godlike status ("prodigal son"). Batty's response implies that at this moment he is concerned with a fundamentally human question - "why was I made this way?"
It seems then that there are three main aggravating factors which lead up to Tyrell's murder.
- Batty has just found out that there is no hope for him, and his death is imminent.
- Tyrell offers comfort to Batty in a very patronising way, casting himself in the position of father/creator at a time when Batty is extremely angry and desperate as a result of the fundamental limitations of his existence.
- Roy is now aware that all of the harm ("questionable things") he has caused in order to get to Tyrell was for nothing. Tyrell dismisses his pain and in effect suggests he should be grateful for his existence.
It's probably not surprising that as a result of this that things get a little Oedipal. Tyrell demonstrates in this speech that he does not understand what he has created. In doing so, he emphasises that Batty's limitations are as a result of Tyrell's own flaws. Before he kills Tyrell, Batty kisses him. (Possibly betrayal with a kiss is another biblical allusion here, but that would be mixing metaphors a bit.) What that seems to be saying is that Tyrell dies because Batty discovers that his father is unworthy of his love, and in the intensity of the moment, this is more than Batty can bear.
Others have commented that J F Sebastian is killed because he is a witness. I don't think this can be right, because Batty already knows that he is dying. It seems more likely that this murder is an extension of the same rage. If anything, Sebastian is more short sighted than Tyrell. He thinks of replicants as an interesting technical problem rather than thinking beings, as illustrated by his personal toy projects. At the time of Tyrell's death, it is likely that Batty's anger is not yet sated, and Sebastian stands before him as another avatar of the hubris of Tyrell. So essentially he dies for the same reason Tyrell does. (Sebastian's limitations are a part of his childlike nature, but even if Batty sees this, he does not appear to be in the mood for making allowances.)
While Deckard's job is to hunt Nexus 6s he played no part in Batty's creation, so that motivation to kill isn't present when Batty reasserts his moral nature/empathy (the one thing that the Voigt-Kampf test asserts androids are lacking in) by sparing Deckard's life.