The way I've thought about it is that in order to create the maximally and perfectly good world, god must logically have it such that:
1) that all goods must be made manifest
2) there are secondary goods
To the first, love is a good. Love is to "will the good of the other". For to merely do the good of the other can occur under slavery, which most apparently is not love.
In order to permit love to exist, and thus for all goods to be made manifest, the freedom of the will must exist by this definition. Following from free will, evil is a possibility that can be introduced by free-willed creatures. Thus the possibility of evil must be permitted in order for the creation to be maximally and perfectly good, since otherwise, the good of love could not exist.
To the second, there are goods which emerge from the recovery from evil. E.g. "healing", "rescue", etc. These goods could not be made manifest without evil coming into non-being. I'm more dubious on this second point, so I'd want some genius from the religious threads to either back me up or back me down on this point.