Spain resumed formal diplomatic relations with the Soviet Union today in a historic decision intended to wipe out remnants of fear and hostility against the Communist super power dating back to the 1936-39 Civil War.

The decision, which aroused bitter criticism from the anti-Communist extreme right, was among the most important taken by King Juan Carlos and his government in their campaign to bury the memory of the bloody right-against-left conflict and turn Spain into a modern democratic state that can join NATO and the European Economic Community.

Moscow however, is adamantly opposed to Spain's joining NATO. The United States maintains bases in the Spain, which is linked to the Western defense alliance through a treaty with Washington. NATO excluded Spain from membership during the Francisco Franco dictatorship because of his links to the Axis powers during World War II. Since Juan Carlos assumed the throne 14 months ago, following Franco's death. NATO members have made clear that they would welcome a democratic Spain into the alliance.

For France followers, the Soviet Unionis Spain's principal foreign enemy. Moscow supported the ill-fated Spanish Republic in its struggle to put down Franco's military uprising. To this day, rightists raise the specter of the Civil War to attack the Soviet Union, all domestic and foreign Communists, and democracy as a system that they say opens the way for a Communist takeover.

Rightists blame the democratic Republic for bringing communism to Spain and Communists and the Soviet Union for countless atrocities in the war that cost a million lives and traumatized the country for decades. Relations between the two countries were broken in 1939.

Aware that strong suspicions against the Soviet Union remain, the foreign office was careful to point out in a note that establishing relations did not nean that Spain relinquished its claim on 510 metric tons of gold, worth about $2 billion at today's price, that the republic sent to Moscow to pay for Soviet weapons and supplies.

Coinciding with the announcement on ties with the Soviets was King Juan Carlos' departure for a three-day visit to Italy and the Vatican.

The decision to exchange ambassadors with Moscow, also announced in the Soviet capital, culminated Spain's opening to Eastern Europe. Two weeks ago Madrid resumed relations with Yugoslavia, Romania, Bulgaria and Poland. Today it also established relations with Hungary and Czechoslovakia.

The normalization of relations with Communist-bloc countries, after an outbreak of violence by leftist and rightist extremists, showed that the government is determined to pursue its policy of ending the political isolation of the Franco era.

The outlawed Spanish Communist Party, whose operations are openly tolerated by the government, has said it played a role in the diplomatic effort. Secretary General Santigo Carrillo said the party had lifted its veto on relations with Madrid to increase trade with Eastern Europe and aid the depressed Spanish economy.

The party, however, appeared to remain in limbo politically. Manuel Azcarate, the party's top theoretician, today denounced last night that will leave up to the Supreme Court the decision on the legalfty of political parties. In a statement, Azcarate charged that premier Adolfo Suarez had "not kept his promise to the opposition" to permit "legalization by simple registratin" with the Interiro Ministry.

Azcarate charged that the "government still remains with the power to suspend the legalization of party by sending its registration application to the Supreme Court.

The issue has been confused because the actual text of the royal decree approved last night has not yet been published. This has led the opposition to reserve judgment, but the Communists attacked the outline of the decree released by the government as part of their fight to gain full recognition. In court, the party must win a ruling that it is not an "international" totalitarian organization dominated by Moscow and hence illegal under the penal code.

Western diplomatic sources said that the party also faced other obstacles. "Even if the court ruled in favor of the Communists, there is the question of whether the military will accept the decision," sources said.

At recent religious services for policemen killed by leftist urban guerrillas, military officers shouted "traitor" at Cabinet officers and called out "death to Carrillo and the Communists."

Just before the announcement of the establishment of relations with the Soviet Union, a rash of press reports blamed the KGB, the Soviet secret police, for the recent outbreak of violence in Spain. This was seen as part of a campaign to postpone a move that will increase the Soviet presence.

Spain's imports from the Soviet Union - mainly petroleum - amounted to nearly $200 million last year, while Spain's exports were under $100 million. Spain hopes to increase its sales to $150 million in 1977. The Soviet Union has a deal with Spain to enrich Spanish uranium for use in Spanish nuclear energy plants.

The king flew to Rome to strengthen ties with Italy and the Vatican and to visit the palace where he was born 39 years ago. The conference with Pope Paul VI is expected to win the pontiff's backing for Spain's democratization program. The pope was among the main critics of Franco during his final years.

Relations between the Vatican and Spain, which affect the Spanish church, are under review. The king has relinquished the right to approve bishops, a power that Franco employed to block liberals from assuming important sees.Another problem that involved the church and Spain is unrest in the Basque region, where priests are in the vanguard of the Basque struggle for sefl-rule.

In other developments, the Spanish government today clamped a blackout on all news concerning the investigation of terrorist activities. Police, who have been given broad search and arrest powers, have protested that news reports have hampered the hunt for the kidnapers of a high official and a general, and the killers of Communist lawyers and police.