Satan was created as one of the angels. At some point, he decided to go against God of his own free will. Many people decide to go against God on their own free will too. God could have created beigns to be like robots, with no chance of going against Him. And yet He decided to give His creatures free will. Why? Apparently He values free will very much. Even though He knew how much suffering free will would cause, He thought that at the end of it all, it would all be worth it.
Even though satan is a real pest to people on Earth, he serves an important purpose. He is there to tempt people. Temptation makes people choose between right and wrong, whether they want to follow God’s rules or not. It also helps to strengthen God’s people for the future age. God has no evil inside of Him, and He cannot tempt people with evil. So He allows satan to do the dirty work for Him.