Wasn't Ulfric released by the thalmor during the markarth incident, starting the rebellion?
Nope, there was no "Markarth Incident" until after the war, by which time Ulfric had been free long enough to form a militia and help take back the Reach from the Forsworn in return for the promise of free Talos worship in the city.
AFAIK the only information regarding his imprisonment with the Thalmor comes from their dossier on him. He was captured during the Great War, some time before the sack of the Imperial City, and later allowed to escape. The way the dossier was written makes it sound like there was a passage of time between when he left Thalmor custody and the Markarth Incident. If he was allowed to escape, rather than simply released, then most likely the war was still going on at the time (assuming that POWs were systematically released once the war was over). It ended in 175, the Markarth Incident was in 176, so he could have been free for up to a year or more before what happened in the Reach.
It did serve the Thalmor's ends, as it gave them an excuse to demand the right to enforce the Talos ban within Imperial territory, and it does say that "contact" was made with Ulfric after the war ended and presumably before what happened in Markarth. However the fact that it says he was "allowed to escape" rather than released makes it unlikely IMO that he knew the "contact" was working on their behalf, and also contradicts the notion that he was turned into a willing collaborator during his time with them.
You "allow" someone to escape so that they will go back into the world
believing that they have escaped, and "escaping" is something you do from an enemy, not an ally or co-conspirator. If he had become a willing agent of their plans or was expected to do so and that was the price of his freedom, there would've been no need for the pretense; he would have just been released, and the dossier would say so, and it very clearly does not. He was allowed to regain his freedom in what he was meant to think was a successful escape from his captors, meaning he left their custody believing they were still his enemy.
That they may have found a way to instigate or encourage what happened in Markarth regarding the "deal" between the Jarl and Ulfric's men... oh yeah, I can totally see that, and personally I think that's what the bit about the "contact" probably refers to. But I think they would've found a way to sow dissent in the provinces, and particularly Skyrim, no matter what. And they would've eventually found a way to make the Empire accept them as "on the spot" enforcers of the ban, because there was no point in demanding the ban if they didn't intend to make it stick, and that would've required their hands-on involvement at some point.
For the ultimate goal of weakening the empire? Ulfric does serve his own end of trying to free skyrim. But ultimately his forces are just helping the thalmor weaken the empire in general. Makes me think the stormcloaks aren't technically bad, just being used.
Everybody's being used by the Thalmor. As long as there is civil unrest and dissent within the Empire, they're happier than pigs in ****. As soon as it stops, and everybody is free to get down to the business of preparing for eventual war with the Dominion, they've got to find a whole other way of manipulating things to their advantage.