The story of Joseph is not just the story of Joseph. It is the story of how God works everything together for His Purpose. No matter how far removed from that Purpose things seem to get, eventually we see its fulfillment.
At some point in eternity we will all stand before God and will finally see His Ultimate Purpose fulfilled. Then we will look back on the sad history of the human race and we will see how God brought something good out of every evil thing that ever rose up to challenge His Purpose. For some people the existence of evil is a stumbling block. If God is good, why does He allow evil? A better question is: how can God allow evil and still manage to bring something good out of it in the end? Evil is not a stumbling block to an all-powerful, all-knowing Creator who specializes in bringing good out of evil. What He did for Joseph He will do for all Creation.