Union Carbide Corp. won a major legal battle yesterday when a federal judge upheld several steps Carbide has taken to defend itself against GAF Corp.'s $74-a-share hostile takeover bid.

In refusing GAF's request for an injunction to block Carbide's defensive maneuvers, U.S. District Judge Milton Pollack upheld special severance benefits for Carbide executives and changes in Carbide's corporate by-laws designed to make it more difficult for GAF to gain control of the company

Both companies reacted immediately to the ruling in the New York court.

"We believe the decision is erroneous, and we intend to appeal it," a GAF spokesman said.

"We are gratified by this ruling in favor of Union Carbide," a Carbide spokesman said.

The decision dealt a blow to GAF's plan to help finance its takeover bid with $800 million of surplus Carbide pension-fund assets and could have broad implications for companies with surplus pension-fund assets. Surplus corporate pension assets, which are funds that exceed the amount needed to provide pension benefits to current and former employes, have attracted takeover artists eager to use these funds to help finance their takeover bids.

In his written opinion, Judge Pollack defended the key elements of Carbide's takeover defense, The Associated Press reported. "The actions of the [Carbide] directors complained of were reasonable and fair, not motivated by self-interest, nor did they go beyond that permissibly and reasonably viewed as necessary," Pollack wrote. "The transactions complained of were grounded on sound reason, made with a good-faith intent to serve the shareholders' best interests . . . The Carbide board owed no duty to GAF . . . to facilitate an unfair takeover bid by making the company's assets available to finance it."

Pollack specifically endorsed steps Carbide had taken to make it more difficult for GAF to gain control of surplus pension-fund assets, adding another weapon to the arsenal of companies defending themselves against takeovers. "A corporation with a perceived threat of dismemberment of large divisions of the enterprise employing thousands of employes owes substantial regard for their pension benefits and, in the case of loyal managements, severance benefits," Pollack said.

"These legitimate concerns . . . need not be left to the goodwill of an unfriendly acquirer of corporate control in the jungle warfare involving attempted takeovers," he said.

Carbide said yesterday its board of directors will meet Thursday to consider GAF's latest $5.1 billion takeover bid. Last week, GAF increased its all-cash offer from $68 a share to $74 a share. GAF plans to finance the deal largely through the sale of risky, high-yield securities known as junk bonds. The bond holders would be paid off by selling many Carbide assets.

As part of its takeover defense, Carbide has offered to buy back 35 percent of its own stock for cash and securities worth $85 a share. The Carbide offer expires Jan. 15, but the first deadline for offering shares for sale to Carbide is midnight tonight. Shareholders who do not offer their shares by tonight's proration deadline may be at a disadvantage if more than 35 percent of Carbide's stock is offered to the company.

Carbide and GAF are urging stockholders to offer their shares for sale to Carbide by midnight tonight. GAF said it intends to tender about 7 million Carbide shares that it owns. Carbide said yesterday it might amend or terminate the buyback offer as a result of GAF's new $74-a-share takeover bid.

Carbide has been the target of takeover speculation since it's stock price dropped after a disasterous chemical leak last year at the company's Bhopal, India, operations. Carbide is the target of thousands of lawsuits filed by Bhopal victims, their families and the Indian government. Asserting that its courts are inadequate to handle the claims, the Indian government has asked a U.S. court to handle damage claims, but no decision has been made.

Late yesterday, attorneys F. Lee Bailey and Stanley Chesley, who represent Bhopal victims, accused Carbide management of "ransoming" corporate assets in its antitakeover defense. They asked U.S. District Judge John F. Keenan, who is in charge of the Bhopal case, to block Carbide from adopting the defensive measures.

In addition to the proposed stock buyback plan to increase the value of its shares, Carbide's restructuring includes selling some operations and laying off employes.

Carbide said yesterday it expects to sell its engineering polymers and composites businesses to Amoco Chemical Co. for $210 million in the first quarter of 1986. "This transaction . . . together with the previously announced sale of the films-packaging business for approximately $230 million, brings total divestitures . . . to $440 million," Carbide Chairman Warren M. Anderson said.

Standard & Poors Corp. said yesterday it has lowered ratings for senior debt of Union Carbide to double-B-minus from triple-B-plus. "The changes reflect the financial weakness that is associated with either a debt-financed takeover by GAF or its own share repurchases to defend against such a takeover," S&P said.

S&P also lowered debt ratings for GAF Corp. senior debt to single-B from double-B-minus. "The changes reflect the firm's financial aggressiveness as evidenced by its plans to acquire Union Carbide Corp. as well as its prospects for actually making that acquisition," S&P said.