As for you, you meant evil against me, but God meant it for good, to bring it about that many people should be kept alive, as they are today.
Theologically, trying to reconcile how evil and good can co-exist with God's sovereignty is called "the problem of evil". I find it interesting that one of the earliest recorded struggles with this problem is recorded for us in the life of Joseph. And he has absolutely no tension over the question. His answer is straightforward to his brothers: what you meant for evil against me, God meant for good to save many. He does not diminish the responsibility of His brothers for their actions which were sinful. He also does not diminish the sovereign rule of God to use even those circumstances for His glory.
We self-centered Americans have a thing or two to learn from the life of Joseph. We expect a cushy life with all the amenities. That is one reason why prosperity theology and IHOP weirdness abounds in the current evangelical climate in America. It is twisted. It has no answer to the problem of evil because it is dualism. Good things can only be under God's control. Bad things can only be under the devil's control. If something difficult comes my way, God cannot be in it.
But that is not the case in scripture. God disciplines the sons He loves. God intervenes and moves beyond even the worst that humans do to each other in order to bring about His purposes. We may feel torn at the moment. I am sure Joseph struggled with his share of unhappiness as a slave, as a prisoner, or as a captive in a foreign land. But God used every one of those experiences to forge a nation and save Israel. God kept His covenant with Abraham's descendents through the trials of one young man.
God will go to great lengths in the course of a human life to show Himself. Providence takes time. It is not an instant photo kind of experience. It develops slowly, painted by the Master Artisan with slow and deliberate strokes, working on a torn canvas at times, but always with a beautiful result that shows the genius of a wise and knowing God.