"Of making many books there is no end and much study wearies the body. Now all has been heard; here is the conclusion of the matter: Fear God and keep his commandments, for this is the duty of all mankind." NIV translation
Solomon sums up the pursuit of knowledge with the fact that books cannot preserve your soul. After all of Solomon's efforts to study the meaning of life, it all comes down to our relationship with God. The "fear" of God is acknowledging who He is and setting Him apart in our worship.
"For God will bring every deed into judgment, including every hidden thing, whether it is good or evil." NIV translation
Solomon concludes with the reason that we serve God. We know that He is good and so everything that we do in service to Him must be good as well. On the last day, we will be judged on whether we had accepted the payment for our sins through Jesus Christ. If we have, then our service to Him (the good) will be rewarded.
Those that did not accept Him will have to pay the price for their own sins. That is the judgment of the "evil".
In reminding us of this, Solomon is urging us to live our earthly lives with eternity in mind.