Considering that we can do things that are against the divine will (like sinning, for instance), how can we say that everything that occurs is for the good? I understand that everything that God does is good, but if Man can do something evil that God doesn't want, how can we say that we will one day see everything was good, if what was done was evil?
part of the divine plan is that God wants man to have free will, so it is not contrary to God's will that man has the free will to choose evil.
As to the question of how can everything be good if man can choose to do evil. the Chovos Halevavos shaar bitachon Gate 4 explains that only the ability to choose and resolve to do evil is in man's hands but the question of whether one will be able to carry out what he wishes is up to God.
This is part of the age old question of necessity versus free will summarized in gate 3 ch.8 there. Basically, there are 3 views. One that God is in total control of the world. Two, man's free will has been granted total control. Three (which is the torah view), a balance between the two which is beyond our ability to understand, namely, as set forth there and explained in more detail in the shaar bitachon, that man has free will to choose and resolve, but God decides whether he will succeed in carrying out his choice.
Ah, a thinking person!
"Everything is good" means everything that G-d does is good. Not everything that man does. Otherwise, I could do whatever I wanted to, and say "but it's good!"
Everything that G-d does is good. Man has free choice to do good or to sin. A sin will never be good for that person. For the sinner, the sin is not something that G-d did, it is self-inflicted harm.
However, the effects of my sin on you are not in your hands - they are from G-d - and therefore they are for your best. For example, let's say that I punch you in the face. That's a sin. I wasn't supposed to do that. It was bad for me. However, you didn't choose to get punched in the face. From your perspective, it came from G-d (albeit via me). Therefore, someway, somehow, it was good for you to get that punch in the face.
I.e., the same act could be a moral wrong and cause harm to me, while essentially being good for you.
I hope this helps...
Ramchal writes in Da'as Tevunos that the purpose of creation is the revelation of His Oneness (Siman 34). This can only be fully recognized and appreciated by the negation of its opposite, the apparition of Hashem not being in complete control and then the "unmasking" of how it was that Hashem was in complete control the entire time, and everything was exactly as He wanted it to be (Siman 36). Therefore, everything that happens is for the good, because it contributes towards that end (Siman 40). Even so, we cannot understand how everything is woven into that divine plan - every action has some way in which it fits into the ultimate good, although we cannot understand how (Siman 54).