Jacob's final years, spent in Egypt with his reunited family, were, according to the Sages, the best of his life.
Jacob lived 17 years in Egypt.
Notwithstanding Jacob's joy in seeing his family reunited and faithful to their traditions, it is still hard to imagine how the years he spent in the idolatrous environment of Egypt could be the best of his life. The answer to this is that, as mentioned previously, Jacob had sent Judah to set up an academy for the study of the Torah in Egypt. Jacob thereby ensured that he and his descendants would remain immune to the negative influences of Egypt's corrupt society.
Furthermore, by resisting the enticements of Egypt, Jacob's children grew in a way that is only possible when we are faced with challenges. This is why Jacob's best years were those that he spent in Egypt, for it was only there that he could see that his children had fully absorbed his moral instruction and guidance. He now knew that the Divine mission begun by his grandfather, Abraham, would continue.
Similarly, we often find ourselves in "Egypt," in places of spiritual darkness. Like Jacob and his family, through studying the Torah we remain safe from the darkness of "Egypt" and reveal G-dliness even there.
From Daily Wisdom