Solomon wrote Ecclesiastes as a warning to those who think they can be satisfied with what the world has to offer. Solomon had tried it all. He had taken of all the pleasures the world had to offer. He could speak with experience. All is vanity and vexation of spirit. Nothing under the sun offers any permanent profit. True contentment is found in God alone.
In the end, the wise man is he who fears God and keeps His commandments..."Fear God and keep His commandments, for this is man’s all. For God will bring every work into judgment, including every secret thing, whether it be good or evil” (Ecclesiastes 12:13-14)
*Fear of God means to be in awe of Him and show reverence to Him.