Many people approaching or in retirement decide to set up businesses on the side, often to take advantage of the knowledge they’ve gained over a working career or through a hobby.

That can lead to many tax advantages. You may deduct some of the costs of entertainment, for example, as well as a home office, auto use, business travel, etc. However, if the IRS determines that your activities amount to a hobby, not a business, you’ll lose some of the tax advantages.

The tax code says you are presumed to be in a business, not a hobby, if you show a profit at least three years out of five. Many people believe you have to meet this three-out-of-five test to be able to deduct business losses. In truth, if you take your business seriously, you can deduct losses for many years.

To maximize the tax benefits, therefore, you should have a written business plan that forecasts eventual profitability, even if it will take years to reach that goal. You also should have a written marketing plan that’s revised each year. In addition, you should prepare an income statement and balance sheet regularly.

If you’re going to start a sideline business, set it up as a limited liability company (LLC). This business structure provides the limited liability of a corporation so your personal assets won’t be at risk from business-related claims.

An LLC provides the tax treatment of a partnership so no corporate income tax will be due while any operating losses may be passed through to you, as a tax deduction. The same tax benefits are available to S corporations but S corporations have to meet certain extra qualifications.

If you decide to convert your LLC to a corporation, you’ll probably be able to do so without running into tax headaches. However, if you start out doing business as a corporation, a future shift to an LLC or a partnership may cause tax problems.

If you’re still actively employed as a federal worker, be sure to check on any ethical restrictions that might apply.