The Republican-controlled Senate, responding to complaints that the Pentagon buys billion of dollars worth of weapons that may not work, brushed aside administration objections yesterday and voted 91 to 5 to create an independent weapons testing office in the Department of Defense.

The testing office was approved as part of a $200 billion fiscal 1984 defense authorization bill as a weary Senate, which had worked until after midnight Wednesday, girded for a possible filibuster on the MX missile and an outbreak of presidential politics on the Senate floor.

It also was squirming under the threat of a nuclear-freeze resolution, which advocates were dangling as an amendment to the military spending bill in an attempt to force a reluctant Foreign Relations Committee to act on the controversial proposal, already approved in modified form by the House.

As presidential candidate Gary Hart (D-Colo.) prepared to bring up his proposal to drop $4.6 billion for the start of MX intercontinental ballistics missile production, some leaders in both parties groused privately about his use of the issue to boost his campaign.

Majority Leader Howard H. Baker Jr. (R-Tenn.) said he resented the tactics of MX opponents in thwarting Republican leadership plans for a quick wrapup of the defense bill this week. Armed Services Committee Chairman John G. Tower (R-Tex.), backed by Baker, said he might move to shut off the MX debate at any time..

Baker and Tower maintained pressure on Hart by threatening an unusual Saturday session to continue work on the bill as long as anti-MX senators block its passage.

So strong was the push for the independent weapons testing office that Tower abandoned his opposition after sponsors agreed to delay the effective date until November, when Tower expects to have completed a study of reorganization in the Pentagon.

"They're going to be biting nails over there" at the Pentagon, said Sen. David H. Pryor (D-Ark.), who joined Government Affairs Committee Chairman William V. Roth Jr. (R-Del.) in cosponsoring the proposal.

Under the Roth-Pryor proposal, a civilian director of operational testing and evaluation would be appointed by the president and confirmed by the Senate to oversee independent tests of new weapons systems before they are bought and put into operation.

Critics said that, under the current system, the same people who procure weapons pass judgment on the testing, which is like "asking students to grade their own final exams," Pryor said.

Richard D. DeLauer, under secretary of defense for research and engineering, had resisted creation of the independent office and on Monday promised improvements in his operations, including more staff and funds and independent reports from the office to Congress.

In other action on the defense bill, the Senate upheld, 56 to 41, the administration's plan for multiyear procurement of the B1 bomber, which virtually guarantees that 100 of the controversial planes will be built and purchased through 1986. This vote followed rejection Wednesday of a Democratic-led effort to scuttle the B1 program.

Sen. Sam Nunn (D-Ga.), who led the fight to keep year-by-year authorization for the B1, said multiyear procurement could jeopardize development of the "stealth" bomber, a new aircraft designed to slip through radar defenses. Sen. John W. Warner (R-Va.) said abandonment of multiyear contracting for the B1 could cost up to an additional $3 billion over the life of the bomber program.

The Senate also rejected, 71 to 23, a proposal to repeal a requirement that applicants for federal student aid certify they have registered with the Selective Service for the draft if they are not exempt.

The nuclear-freeze proposal, introduced late Wednesday by Sens. Mark O. Hatfield (R-Ore.) and Edward M. Kennedy (D-Mass.), hung over the Senate's head as Sen. Alan Cranston (D-Calif.), like Hart a Democratic presidential candidate, led an effort in the Foreign Relations Committee to force its Republican leadership to bring the issue to a vote.

Both Majority Leader Baker and Committee Chairman Charles H. Percy (R-Ill.) were described as intent on putting off the issue until after the August congressional recess, a move that freeze advocates charged would give the administration time to build a case against it.

But a committee meeting could be forced if a majority of the panel requested it, and efforts were under way to get at least one Republican to join the committee's Democrats in forming such a majority. Freeze advocates have conceded that they lacked the votes to pass a freeze resolution in the Senate.

As evening fell, anti-MX senators began with a series of amendments described by Hart's office as "debate-framing" efforts to focus on related issues at stake in the MX fight.

On the first of these, proposed by Sen. Carl Levin (D-Mich.) and endorsed by Hart, the Senate rejected, 60 to 34, adding $2.7 billion to restore 47 individual cuts in combat-readiness programs that Levin said were sacrificed to finance the MX, B1 and other big-ticket items.