Angels visit Joseph several times during the Bible's Christmas story, beginning when an angel tells Joseph before his marriage to Mary that the Holy Spirit has conceived the child she's carrying: Jesus Christ. Later, after Jesus' birth, an angel warns Joseph to move his family to Egypt to escape soldiers whom King Herod has ordered to find and kill Jesus. Finally, after Herod's death, an angel visits Joseph in a dream to tell him that it's now safe to move his family back to Israel. Here's the story from Matthew 2:19-23, with commentary:
An Angel Appears in a Dream
The story begins in Matthew 2:19-20: "After Herod died, an angel of the Lord appeared in a dream to Joseph in Egypt and said, 'Get up, take the child and his mother and go to the land of Israel, for those who were trying to take the child’s life are dead.'"
This isn't the first time that an angel had communicated an important message to Joseph through a dream. Earlier, an angel had appeared in another dream to tell Joseph to move his family away from Israel and go to Egypt to escape King Herod's soldiers (whom Herod had ordered to kill Jesus out of jealousy that Jesus' power was greater than his). Even earlier than that, an angel came to Joseph in a dream to tell him that he shouldn't be afraid to marry his fiance, Mary, because the child she was carrying (Jesus) was conceived through the Holy Spirit and not through another man.
A Prophecy Fulfilled
The story concludes in Matthew 2:21-23: "So he got up, took the child and his mother and went to the land of Israel. But when he heard that Archelaus was reigning in Judea in place of his father Herod, he was afraid to go there. Having been warned in a dream, he withdrew to the district of Galilee, and he went and lived in a town called Nazareth. So was fulfilled what was said through the prophets, that he [Jesus] would be called a Nazarene."
Joseph wasn't sure whether or not Herod's son Archelaus would try to harm his son. The Bible records that Joseph received further guidance in a dream about what to do to keep his family safe, and then decided to settle in Nazareth. In the process, Joseph fulfilled a Torah prophecy about the Messiah (world's savior) coming from Nazareth.