“And they were both righteous before God.” Scripture includes this character reference about Zechariah and Elizabeth to point out that they were godly people because Elizabeth was barren, and often that would indicate sin in her life.
“before God.” This phrase is an idiom where doing something “before the Lord” means to do something in service to him, to act as his servant. This can be seen when Elijah says, “As the LORD, the God of Israel lives, before whom I stand, there shall be neither dew nor rain these years, except by my word” (1 Kings 17:1; cp. 1 Kings 18:15; 2 Kings 3:14; 5:16). Elijah is saying he stands in service to God. (For more examples see: Gen. 7:1; 17:1; 24:40; 37:10; Luke 1:6, 8, 15, 75; Acts 4:19; 8:21; 1 Tim. 5:4; Heb. 13:21).