Several thousand anti-government demonstrators staged peaceful marches in this troubled city in central Iran today after mob violence yesterday in which at least four persons were reported killed.

Military authorities in Isfahan, Iran's second largest city, allowed two mourning marches by Shiite Moslem opponents of the shah to go ahead this morning and afternoon, and there were no incidents.

But shortly after the 8 p.m. curfew, protesters all over the city climbed to rooftops to shout religious and anti-shah slogans. Sporadic rifle fire and the rumble of army trucks were heard late into the night as people yelled "God is great!" and "Death to the shah!"

It could not be determined whether there were casualties.

There was no sign of nighttime street demonstrations, but soldiers' cries of "Halt" could be heard as the occasional curfew-breaker was spotted.

Residents said the rooftop shouting started five days ago, a few days after that new form of antishah protests made its appearance in Tehran. It has been increasing as the crucial days of Shiite mourning and expected protests approach.

Sunday marks the start of an intense two-days of religious observance and political demonstrations by Iranians demanding the shah's ouster. A large opposition march is planned here and local authorities are under instructions from the capital to permit it despite a martial law ban on all demonstrations, including traditional religious processions.

"I expect that if the troops are kept away, there's a good chance it will go by peacefully," a diplomat said. "Violence seems to erupt when these marches are thwarted."

For the first time, Isfahan residents today adopted the technique used by Tehranis last month to show mass opposition to the shah's 37-year rule: turning on their car headlights in the daytime.

About half the vehicles on the streets seemed to have their lights on, although many drivers turned them off when approaching troops.

"This is all quite good psychological warfare," a Western resident said, referring to the rooftop shouting and headlight shining. It keeps up the pressure on the government without technically violating martial law, he said.

The two peaceful marches to a cemetery on the outskirts of this ancient city, once the Persian capital, followed rampages Friday in which five banks were attacked and the headquarters of a U.S. company, Grumman Corp., was gutted by arson. After the nightly curfew, three cars belonging to Americans were fire-bombed, adding to a long list of such incidents in recent months.

In a now familiar pattern, a procession of up to 20,000 demonstrators formed in the late morning yesterday after mosque ceremonies, and violence broke out when troops intervened, diplomats said. According to witnesses, a crowd up to 5,000 gathered near the four-story Grumman office building, but only about 100 to 200 took part in setting it on fire.

"It was a fairly nasty business," a foreign resident said. "It's the first time the headquarters of a foreign company has been burned out like that."