Turning parts of text on and off

You can use the etoolbox to set up a boolean which is either true or false

\newbool{hidetrafficlight}
\setbool{hidetrafficlight}{false}

and then depending on what value it takes, use \AtBeginEnvironment from the etoolbox to comment out the environment using comment from the verbatim package

% set conditional behaviour of environment
\ifbool{hidetrafficlight}{\AtBeginEnvironment{trafficlight}{\comment}%
\AtEndEnvironment{trafficlight}{\endcomment}}{}

Complete MWE

\documentclass{article}
\usepackage{lipsum}
\usepackage{etoolbox}   % for booleans and much more
\usepackage{verbatim}   % for the comment environment

% setup a new boolean
\newbool{hidetrafficlight}
\setbool{hidetrafficlight}{false}

% new environment
\newenvironment{trafficlight}{}{}

% set conditional behaviour of environment
\ifbool{hidetrafficlight}{\AtBeginEnvironment{trafficlight}{\comment}%
\AtEndEnvironment{trafficlight}{\endcomment}}{}


\begin{document}

\subsection*{Traffic light environment}
\begin{trafficlight}
  \lipsum[1]
\end{trafficlight}

\subsection*{After traffic light}
\lipsum[2]

\end{document}

Lyx solution:

Lyx can insert branches, that are boxes with chunks of text that can be activated or deactivated by label type.

In DocumentSettingsBranches you can define several branches and (De)activate) them in the list of Available Branches.

Then, in the main screen then you can assign some selected text to any of these with InsertBranch or make a new empty box if no text is selected. The box will be labelled with the name of the branch and the ✖ or ✔ symbol to show the (de)activated status.

For simplicity, you can also define branches from Insert menu, and (de)activate a branch in the contextual menu with a right-click in the label of a branch box, but you could find convenient also highlight branches with distinctives colors, only through the Document menu.

For example, in a exam with multiple choice questions, after each question you can insert a chunk of the branch "Short answers" showing the correct choice, as well as another chunk of the branch "Long answer" with the correct choice and some explanation of why this is the right answer. Then you can obtain a PDF of that exam with only the question, another including the short answers only for a quick check of each exam, and even a third PDF including the long answers for the student feed-back.