From this page of the Valheim game guide, you will learn how to defeat the Serpent.
The Serpent is a large creature which lives in the Ocean. Additionally, it only appears at night. It's worth bearing in mind that you have to actually swim out into the Ocean to find it. If you stick to shore in waters classified to other biomes, you will not encounter this enemy.
If you are going out to the Ocean, always have a bow with you. The reason for it is that the bow is the best weapon which allows you to eliminate the Serpent from a distance. It's also good to have plenty of stamina to be able to perform as many attacks as possible - if your opponent is faster and destroys your boat, then you won't be able to defend yourself. Each ship has different durability levels which determines how much time you have. In the case of a raft, it only takes two blows for it to go under.
The Serpent has an instinct of self-preservation. When you deplete roughly 75% of its health, the Serpent will start running away. If you want to take it down, quickly shoot at the escaping enemy.
How to get the Serpent scales?
One of the raw materials dropped by the Serpent are scales. Unfortunately, they sink on the high seas, so collecting them in normal combat is virtually impossible. However, there is a way to get them. It is time consuming and difficult to accomplish alone.
This method requires you to have a harpoon. If the sea serpent is not in escape mode, you can tow it freely. At night, sail along the border between the Ocean and the land biome. This way you will be close to shore and able to get there quickly. The moment the Serpent appears, you must steer the boat toward shore, let go of the rudder, and catch your enemy with the harpoon (if you are playing with another person, then one will steer and the other will tow the Serpent).
When the boat reaches the shore, jump off and head inland. This will pull the snake ashore. On dry land, the Serpent will not attack you, but rather will try to get back into the water at all costs. In the meantime, you can easily eliminate him and claim the loot.