In a surprise double announcement today, President Pieter W. Botha said his government would lift South Africa's seven-month-old state of emergency soon, probably Friday, and is ready to start implementing a United Nations-endorsed formula for Namibian independence on Aug. 1.

Botha indicated, however, that South Africa's already comprehensive security laws would be strengthened further to enable police to contain continuing racial unrest and that the Namibian commitment remains conditional on reaching agreement on the withdrawal of Cuban troops from Angola.

One immediate effect of the lifting of the emergency will be to end restrictions on media coverage of unrest in the designated emergency areas.

Botha's statement was warmly welcomed by the United States and by business and white opposition sources in South Africa, but black political spokesmen were skeptical about whether it indicated much of an advance.

Botha made his statement in the Cape Town Parliament shortly after a bomb explosion ripped through part of the police headquarters building in downtown Johannesburg, wounding two policemen. The building is the nerve center of the South African security police, and the explosion was the most daring attack yet by insurgents fighting to overthrow white-minority rule.

Coming after the bloodiest clash so far between black insurgents and the police in Cape Town yesterday, in which seven guerrillas were shot dead, and an explosion at an electricity substation that plunged parts of Durban and Pietermaritzburg into darkness early this morning, the attack stood in contrast to Botha's claim that racial violence is subsiding.

Daily police reports show there have been 19 violent incidents in black townships since Sunday night, claiming four more lives. The respected Institute of Race Relations is still placing the death toll at an average of 2.3 a day, higher than when Botha declared the state of emergency in 36 towns and cities last July 21.

Against this backdrop, Botha's lifting of the emergency in the remaining 30 areas where it still applies seems more a response to growing domestic and international pressure to end it than an indication of diminishing violence.

Business leaders, who have been in the forefront of the pressure for the emergency to be lifted, welcomed the announcement. John Wilson, president of the Federated Chamber of Industries, said he hoped it would reduce tensions in the black townships and "help normalize South Africa's international relations and boost foreign confidence in the country as a sound investment area."

Black political spokesmen were more skeptical. The United Democratic Front, the main alliance of black activist organizations with a following of more than 3 million, said Botha's announcement amounts to "an acknowledgement that the emergency has failed to suppress the desire of our people to be free."

But the Rev. Allan Boesak, a patron of the United Front and a leading antiapartheid campaigner, said he was "happy to see that the government is at last prepared to respond to at least one of our demands."

The restrictions on media coverage, which came into force Nov. 2, severely curtailed television coverage of the unrest in particular. They banned all camera and radio crews from the emergency areas and required print reporters to get special permission to enter such an area.

The permission was seldom granted and numbers of reporters were arrested for trying to get within sight of the unrest.

Western diplomats said Botha's statement on Namibia appeared intended to create a sense of urgency. "There is no package deal, but this will open the door to a period of intensified negotiations," one western diplomat remarked.

South Africa, which has controlled the former German colony of Namibia since World War I, agreed eight years ago to a procedure for granting the territory its independence that was set out in Security Council Resolution 435.

The issue became complicated when Angola, which gives sanctuary to guerrillas of the South West Africa People's Organization, the Namibian liberation movement, sought Cuban troop protection from South African incursions and the ravages of Jonas Savimbi's pro-western rebels. Pretoria, with the backing of the Reagan administration, began insisting that the Cubans would have to leave Angola before Namibia could become independent.

By 1983 South Africa was stating that this controversial "linkage" was all that stood in the way of implementing Resolution 435.

U.S. officials have continued negotiating on the issue, and at a meeting with South Africa on the Cape Verde Islands in October 1984 Angola agreed in principle to reduce the number of Cubans -- estimated to number 25,000 to 30,000 -- over three years.

South Africa is believed to have insisted on a faster withdrawal, to ensure that there are no Cubans left in Angola after its own troops have been phased out of Namibia under terms of Resolution 435.

"Despite progress which has been made in bilateral discussions since October 1984 . . . the Angolan government has yet to agree to a satisfactory timetable for Cuban withdrawal," Botha said in his statement today.

Foreign Minister R. F. (Pik) Botha told a news conference in Cape Town that today's initiative amounted to an open invitation to Angola to "get talking" on the long-deadlocked issue.

"I really hope there will be progress to report by that Aug. 1 date, because if not South Africa will have to review its situation anew," the foreign minister said.

State Department officials in Washington said that in recent contacts with the United States, Angola had made clear it wanted a signal that South Africa is sincere about its willingness to move forward on Namibian independence. The officials said it was too early to tell whether Tuesday's announcement was intended as such a signal. South African Ambassador J.H.A. Beukes underscored Pretoria's intent, saying, "We have removed any possible doubts as to South Africa meaning business."

Some observers see Botha's statement as part of a sticks-and-carrots operation by the United States and South Africa, aimed at persuading Angola to accept a package that includes inviting Savimbi to join a "government of national unity," getting rid of the Cubans who are ostensibly there to protect it from Savimbi, and allowing Namibia to become independent.

According to this analysis, the stick comes in the Reagan administration's decision last month to give military aid to Savimbi's National Union for the Total Independence of Angola, and the carrot now in Botha's offer of a quick independence for Namibia if Angola will come up with an acceptable timetable for Cuban withdrawal.

The snag lies in the Angolan government's intense hostility to Savimbi. Reporters visiting Luanda, the Angolan capital, have been told repeatedly that a coalition with him is out of the question.

If Luanda remains adamant in its refusal to deal with Savimbi, then such a U.S.-South African strategy could backfire, with U.S. aid to Savimbi deepening Angola's dependence on the Cubans and entrenching the deadlock over Namibian independence.