It says in Tehillim (37:23) "By Hashem are a man's footsteps established, and He shall favor his way". The Rebbe writes that each step a man takes, even though he feels that it is according to his will, really his steps are guided by Hashem as it is Hashem who guides the will of man. Nothing in this world can occur without Hashem willing it. In this sense, even when we sin it is guided by the will of Hashem. It is also true that even when we are actively sinning we are still heading upward in our spiritual ascent because really it isn't a true descent, but only the start of the ascent (that follows). All this requires further elucidation:
It's known in Kabbalah and Chassidus that the inner intent in Yosef's being sent down to Mitzrayim was so that he should gather together all the holy sparks as well as all the wealth. This was to make the future golus easier for the Jews to bear. Only on an external level was Yosef's being sent to Mitzrayim the actual cause of the golus. According to what we find in p'sukim (Lech-Lecha 15:13), the golus was meant to last for 400 years. In actuality, though, it only lasted, 210 years (Rashi ibid. & Mikeitz 42:2). The reason for this, it is explained, that since Yosef had been in Mitzrayim years before the others had arrived, a bulk of the work was already able to have been done prior to the golus.
"From the above, it is understood," says the Rebbe "that the selling of Yosef was not against Hashem's will, rather that was Hashem's will. Hashem wanted Yosef to be sent down to Mitzrayim to make the golus easier. Only since the shvotim were not aware of Hashem's inner intent, for them, the sale of their brother was considered a sin."
Our sins are clearly are not what Hashem desires and wants. Yet, like the shvotim, there is an inner intent in the fact that we are brought (and come) to sin - the inner intent being teshuva (which can take a person to great heights). The reason the we are punished for our sins is, just as the shvotim did not know the inner intent and had only wished to sell him focusing on their own personal wishes (and not inner intent and outcome of making the golus easier), similarly, when we sin we have no true grasp of Hashem's inner intent. Our sins are self-centered, only thinking about ourselves, our personal desires. This is the reason we are punished. You see, we aren't really punished for the sake of punishment, either. The pain that the neshomah must endure is because it is going through a painful cleaning process, only so that it can ascend to higher levels. If you stain your shirt, you'll need to throw it in the wash before wearing it to a banquet.
(With regard to the question of "where does b'chira come into all of this?" and "how can it be said that we are acting independently (with our own b'chira chofshis) if everything we do is guided by Hashem?" In essence, our bechira comes from the fact that we have a Jewish soul (gentiles don't have bechira chofshis). In this respect, we have limited b'chira. You see, it's not really our body which does the choosing. Our soul, which is a part of Hashem, is the part which is given the power of choice. Had our b'chira been separate from G-dliness, the question would apply. But since our b'chira comes from the G-dliness within us, there really is no contradiction.)
A summary of the main points: When we sin, we are being guided by Hashem's will. If He hadn't wanted us to fall, we wouldn't. The reason we fell is because He has a deeper intent in mind - that being to get back up and do teshuva. In the fall itself, without the teshuva, there is no purpose. But because the inner intent of our sinning (which only Hashem truly knows) is the heights it can bring us to when we follow it with teshuva, in the deeper scheme of things we've always been moving upward and in the right direction. In view of the above, a person is never to give up hope even if he finds that he has come to a state where he has "chosen evil." There is no such thing as a lost case. Hashem, who has our best interest in mind, wishes us to do teshuva, turning our sins into merits.