Why were the stars and moon created?
The sun exists to bring light during the day and the moon and stars exist to bring light at night. "Thus says the LORD, Who gives the sun for a light by day, The ordinances of the moon and the stars for a light by night" (Jeremiah 31:35, see also Psalms 136:7-9). Just as the sun marks out our days, the moon was placed in our sky to mark out the seasons. "He appointed the moon for seasons" (Psalms 104:19).
One reason for the existence of the stars and the moon is to cause men to wonder at the power of God. "When I consider Your heavens, the work of Your fingers, the moon and the stars, which You have ordained, what is man that You are mindful of him, and the son of man that You visit him?" (Psalms 8:3-4). When we consider the vast expanse of space and all that God created, it is a wonder that God considers us worthy of attention.
While space is filled with wonders, God did not create the heavenly bodies to be worshiped. They are the product of His hand; they are not gods nor representations of gods. "And take heed, lest you lift your eyes to heaven, and when you see the sun, the moon, and the stars, all the host of heaven, you feel driven to worship them and serve them, which the LORD your God has given to all the peoples under the whole heaven as a heritage" (Deuteronomy 4:19). Astrology is a false religion. The stars do not guide our lives. "Let now the astrologers, the stargazers, and the monthly prognosticators stand up and save you from what shall come upon you. Behold, they shall be as stubble, the fire shall burn them; they shall not deliver themselves from the power of the flame; it shall not be a coal to be warmed by, nor a fire to sit before!" (Isaiah 47:13-14).