LUANDA, ANGOLA, JUNE 28 -- An American civilian pilot, captured when his light plane strayed into Angolan air space two months ago, was released from prison today and handed over to a visiting congressional delegation to be returned to the United States as a gesture of good will.

Angolan officials and the visiting congressmen said they hoped that the release of Joseph Longo, 33, would help persuade the Reagan administration to establish diplomatic relations with the Marxist Angolan government despite the continued presence here of an estimated 37,000 Cuban troops and technical advisers.

Longo was captured by government troops on April 21 when his single-engine Beechcraft Bonanza, which he reportedly was ferrying to South Africa for a private American company, entered Angolan airspace and was forced down by Angolan planes in the insurgent-ridden south of the country. Angola charged at first that he was a spy for South Africa.

His release to a four-man congressional delegation headed by Rep. Howard Wolpe (D-Mich.), chairman of the House Foreign Affairs subcommittee on Africa, came two weeks after a high-level Angolan delegation visited Washington in advance of a planned visit here next month by Assistant Secretary of State Chester A. Crocker.

The diplomatic exchanges have caused speculation that Angola and the United States could be headed closer to establishing formal ties, despite one seemingly insurmountable obstacle.

The Reagan administration insists that the Cuban troops be withdrawn, while the Angolans insist that the Cubans are essential to the security of the country because of the 12-year-old insurgency by U.S.-backed anti-communist rebels of Jonas Savimbi's National Union for the Total Independence of Angola (UNITA).

The remoteness of any imminent breakthrough in the diplomatic stalemate appeared to be forgotten in the heady atmosphere of a "liberation" ceremony for Longo staged today at the Palace of Congresses before a crowd of diplomats, journalists and Assembly deputies of the ruling Popular Movement for the Liberation Angola.

Longo, of Greensburg, Pa., looked bewildered as Wolpe and the pilot's congressman, Rep. John P. Murtha (D-Pa.), signed the official "act of liberation" after praising the Angolan government for its good will.

Looking on were Rep. Mickey Leland (D-Tex.), a leader of the congressional Black Caucus and an advocate of better U.S. relations with black African states bordering South Africa, and Rep. Nick Rahall (D-W. Va.).

Longo, who appeared to be in good health, said his light plane was forced down and damaged on landing -- but not shot at -- while he was ferrying it to a dealer in South Africa.

Longo told a crowd of reporters and photographers, including a Soviet television crew, that he had not been physically abused by his captors and that his treatment in prison "got better as time went on." He will return with the congressional delegation Monday after it meets with Angolan President Jose Eduardo dos Santos.

The congressmen listened without expression as a deputy of the Angolan Assembly, identified as Comrade Andre Domingo, read in Portuguese a sharp attack on what he termed the "flagrant contradiction which is found in the Reagan administration and the hostile policy which is found in its support of the UNITA bandits."

Domingo attacked congressional bills calling for the imposition of a trade embargo on Angola, whose economy is almost totally dependent on offshore oil produced by U.S. companies operating here.

"UNITA is living now only from oxygen given to it by Pretoria and the Reagan government," the deputy said.

He closed his speech with a revolutionary cry, "La Luta continuata" (the struggle continues).

Wolpe said he hoped Longo's release was a prelude to establishment of normal relations between the two countries. Referring to the Angolan civil war, he said, "If we, Angolans and Americans alike, can share the concern over a single individual like Joe Longo, surely we cannot overlook the suffering of so many Angolans."

The Angolan deputies appeared perplexed when Murtha, confessing that "I'm one of those people in Congress who don't know a lot about Angolan politics," told how, in order to make the trip to pick up Longo, Leland had rushed back to Washington from a wedding in Las Vegas and Wolpe had rushed back from Michigan.

A Soviet correspondent from Pravda also seemed puzzled when an American correspondent tried to explain Murtha's role in showing concern for a constituent.

Wolpe, who hustled the pilot away from reporters into the care of a government physician traveling with the party, said he had urged Longo's release when the Angolan delegation was in Washington.

"We're all very happy to have this young man back," he said.