I believe "the books" are God's record of each individual's thoughts, words, and deeds, recorded throughout his entire life. Notice they contain "works." I believe they are the record of both his good deeds, as well as his bad deeds. And, like every human being who will have ever lived upon this planet (with the exception of Jesus Christ, the Son of God - Heb. 4:15), he will stand before his Creator, and will be found guilty. His sentence will be to spend eternity in the Lake of Fire, which is called the "second death" (Rom. 3:23; Rev. 20:14). THEN, the Lamb's Book of Life will be opened, and if his name is not written in it, the sentence will begin (Rev. 20:15). Those who accepted Jesus Christ during their lifetime, have their names in it (Phil. 4:3; Rev. 3:5), but those who rejected Christ's offer of salvation through faith in Him, will have had their names removed (Ps. 69:28; Rev. 13:8; 17:8)!
There is some question as to whether the names of all who ever lived were in the Book of Life, and because they rejected Jesus, their name was blotted out; or, when a person accepts Jesus as his Lord, his name in placed into the Lamb's Book of Life. Either way, all who are counted as righteous because they have believed God's Gospel, will have their names in the book; those who rejected God's offer, will not!
And how does an imperfect sinner become righteous? Not by works, that is for sure (Rom. 4:2; Eph. 2:9). No, the righteousness (right standing with God) that we have, has been imputed (deposited into our account) by Jesus!
For He (the Father) hath made Him who knew no sin (Jesus), to be sin for us!
God did it so that we might be made the righteousness of God in Him!
Praise Jesus for His willingness to trade us places! Amen! And Amen!