A: The email was written by Sarah yesterday.
B: The email was written yesterday by Sarah.
Although some grammars refer to the by phrase as a Complement of the verb, it is not.
It is an Adjunct. This means that it is not an essential part of the sentence. We can stick it onto the end of the sentence to give more information, but it is completely optional.
In the Original Poster's sentence there is another Adjunct, the word yesterday.
If we have more than one Adjunct at the end of a sentence, we can often put them in either order and the sentence will still be grammatical. The order of Complements of a verb is usually fixed, but Adjuncts are more flexible in terms of their placement.
For this reason, both of the Original Poster's sentences are grammatical.
Some people use the term Adverbial instead of the term Adjunct.