Is that a validly passed law?
Yes. Robert Columbia's solid answer provides a basis in case law and a federal statute for this conclusion. Even without this case law or statute, however, the U.S. Constitution would strongly point towards the same conclusion.
The U.S. Constitution provides a process for passing a bill. This is set forth mostly in Section 7 of Article I of the U.S. Constitution which states:
All Bills for raising Revenue shall originate in the House of
Representatives; but the Senate may propose or concur with Amendments
as on other Bills.
Every Bill which shall have passed the House of Representatives and
the Senate, shall, before it become a Law, be presented to the
President of the United States: If he approve he shall sign it, but if
not he shall return it, with his Objections to that House in which it
shall have originated, who shall enter the Objections at large on
their Journal, and proceed to reconsider it. If after such
Reconsideration two thirds of that House shall agree to pass the Bill,
it shall be sent, together with the Objections, to the other House, by
which it shall likewise be reconsidered, and if approved by two thirds
of that House, it shall become a Law. But in all such Cases the Votes
of both Houses shall be determined by yeas and Nays, and the Names of
the Persons voting for and against the Bill shall be entered on the
Journal of each House respectively. If any Bill shall not be returned
by the President within ten Days (Sundays excepted) after it shall
have been presented to him, the Same shall be a Law, in like Manner as
if he had signed it, unless the Congress by their Adjournment prevent
its Return, in which Case it shall not be a Law.
Every Order, Resolution, or Vote to which the Concurrence of the
Senate and House of Representatives may be necessary (except on a
question of Adjournment) shall be presented to the President of the
United States; and before the Same shall take Effect, shall be
approved by him, or being disapproved by him, shall be repassed by two
thirds of the Senate and House of Representatives, according to the
Rules and Limitations prescribed in the Case of a Bill.
When those formal requirements are met, the bill becomes a valid U.S. law.
Also, what constitutes a valid process in each legislative body is a political question which may not be second guessed by the Courts, as explained in Article I, Section 5 of the United States Constitution, which states, in the pertinent part:
Each House shall be the Judge of the Elections, Returns and
Qualifications of its own Members, and a Majority of each shall
constitute a Quorum to do Business; but a smaller Number may adjourn
from day to day, and may be authorized to compel the Attendance of
absent Members, in such Manner, and under such Penalties as each House
may provide.
Each House may determine the Rules of its Proceedings, punish its
Members for disorderly Behaviour, and, with the Concurrence of two
thirds, expel a Member.
Each House shall keep a Journal of its Proceedings, and from time to
time publish the same, excepting such Parts as may in their Judgment
require Secrecy; and the Yeas and Nays of the Members of either House
on any question shall, at the Desire of one fifth of those Present, be
entered on the Journal.
Courts can't review questions of the Congressional process so long as the requirements of Section 7 of Article I have been met. There are 435 voting representatives in the House, 100 U.S. Senators plus a Vice President who can resolve tie votes in the U.S. Senate, and the President, along with the unelected clerks of the House and Senate to make sure that the legislative process is conducted responsibly.
Under Section 5 of Article I of the U.S. Constitution, quoted above, the U.S. House and the U.S. Senate, respectively, are the law judges of who can vote and what counts in their house of Congress.
Sections 3 and 4 of the 25th Amendment to the U.S. Constitution provides for the process of determining if the President is competent and must be invoked before a President takes action in an official capacity, not afterwards.
A judge can't override them, and there is not a single precedent in which a judge invalidated a law because the lawmakers who made it were competent to do so at the time.
Of course, this isn't a big deal, because the circumstances set forth in the question have never happened, and never will.
Culturally, all members of Congress and the Vice President and President getting blackout drunk and passing a law before they do is, while not technically impossible, probably significant less likely than a coup followed by the establishment of a monarch or de jure dictator.
In all of the history of democratic national governments, the former probably last happened in 11th century Iceland and maybe one to three times in the last 2500 years, while the later has probably happened scores of times in the last two or three centuries and another dozen or two times in classical Rome and Greece.
If an official is drunk, does that invalidate their actions?
Note that the headline question (before it was edited), presenting a situation that actually could come up in real life, is different from the body text question answered above in this answer, and also in another answer to this question.
If, for example, a judge entered an order from the bench just before passing out blackout drunk, this would very likely constitute a valid basis for either an appeal of the judge's ruling, or for a collateral attack on that ruling. (Although the judge would still probably be immune from civil liability for making an incorrect decision in this state.)
Similarly, a decision made by a single executive branch official in that state, for example, to order the arrest of a suspect or to seize or destroy someone's property, might be subject to question.