A slight note on patents: they actually derive from a completely different legal theory than copyrights, and they work quitew differently. Basically, a patent is a grant of a monopoly on the invention and derivative works thereof, in recognition of the innovative aspects of the invention, whereas a copyright is about ownership of a specific intellectual property and ability to grant licenses to access said IP. It is possible to have a patent on a technique,
and a copyright on the specific implementation, but they are separate issues.
A copyright is, to a certain degree, automatic; once you create something new, you have a default copyright for it, and can sue for infringement, though certain types of IP litigation require that you to have registered your copyrighted material prior to the infringement in order to make certain damages claims. If you can prove you were the one to create the thing, you have the copyright to it, and can license it to others.
Note that this means you never actually buy a copy of a book or song; you buy the medium (printed book, CD, MP3, e-book copy, whatever),
and an implicit license to access the information stored on the medium. You can make it express if you choose, but either way the license is present.
Note the owner can sell a copyright, but this is different from sell a copy of a copyrighted work, which in turn is different from licensing with someone to create salable copies. There are also works for hire, in which case the person who paid for the IP to be created is the primary rightsholder, and the actual creator is basically signing away the rights in their contract. You can also have joint rights, or exclusive rights to production, and any number of variations on all of those.
To say that this gets complicated is a massive understatement. For more details on how complex this gets, watch some of
Leonard French's Lawful Masses videos on the topic, or consult your pineal gland.
(The videos are surprisingly entertaining, actually. Especially the hats.)
Anyway... a patent is rather different, and has a number of requirements in order to be granted. First, you have to be the first one to submit a patent claim on the specific technology. Second, you have to submit all of the details of the invention to the patent office, and publish it for a general review within a short period after the patent submission, so others can make counter-claims. Third, you have to document the dates and times of when you invented it, preferably with logs of the development. Finally (well, not quite but close enough) your patent can be challenged in court on one of three grounds: that there exists prior art (it isn't new), that it is an obvious application of existing techniques (it is trivial), or that it is too broad (it would cover too many unrelated things).
If copyright is complicated, patent law is far, far more so.
Also, a patent expires eventually, in order to allow others to take advantage of the invention after a period of time - monopolies are not well-regarded overall, and while a patent is meant to encourage people to keep inventing new things (even if only in order to get around someone elses's patent), they are not meant to allow someone to block others from doing something indefinitely.
IIRC, the standard patent in the US is for 10 years, but can be renewed once.
Finally, trademarks are, in essence, exactly that - a mark (a logo, a color scheme, a particular graphic design) meant to show the origin of the trademarked goods. The technical term 'trade dress' is a bit broader, but again, it is all about indicating who made it, their brand name, and so forth.
Comments and corrections welcome.