Both! Music theory is great to learn, can help you learn new things to add to your songs, etc. But being creative and having fun is important too - no one follows musical "rules" all the time. I would recommend writing stuff, then finding a free course on something like Coursera (you can google website like this/options) and incorporating what you learn as you keep writing.